Python 筆記 #13# Pandas: Viewing Data

來源:互聯網
上載者:User

標籤:tail   筆記   href   詳細   1.5   tran   describe   python   frame   

感覺很詳細:資料分析:pandas 基礎

 

import pandas as pdimport numpy as npimport matplotlib.pyplot as pltdates = pd.date_range(‘20180116‘, periods=3) # 建立 16 17 18 等六個日期df = pd.DataFrame(np.random.randn(3,4), index=dates, columns=list(‘ABCD‘)) # 這是二維的,類似於一個表!# 通過 numpy 隨機了一個 3 * 4 的資料,這和行數、列數是相對應的# print(df)#                    A         B         C         D# 2018-01-16 -0.139759  0.857653  0.754470  0.224313# 2018-01-17  1.565070  0.521973 -1.265168 -0.278524# 2018-01-18 -0.668574 -0.527155  0.877785 -1.123334# print(df.head(1)) # 預設值是 5#                    A         B         C         D# 2018-01-16 -0.039203  1.211976  0.664805  0.307147df.tail(5) # 同上,顧名思義# print(df.index) # 顧名思義 + 1# print(df.columns)# DatetimeIndex([‘2018-01-16‘, ‘2018-01-17‘, ‘2018-01-18‘], dtype=‘datetime64[ns]‘, freq=‘D‘)# Index([‘A‘, ‘B‘, ‘C‘, ‘D‘], dtype=‘object‘)# print(df.describe()) # 對每列資料做一些簡單的統計學處理#               A         B         C         D# count  3.000000  3.000000  3.000000  3.000000# mean  -0.163883 -0.107242 -0.621706  0.618341# std    0.360742  0.429078  0.800366  0.609524# min   -0.505212 -0.502887 -1.352274  0.055032# 25%   -0.352602 -0.335291 -1.049444  0.294803# 50%   -0.199991 -0.167695 -0.746613  0.534574# 75%    0.006782  0.090581 -0.256421  0.899995# max    0.213556  0.348857  0.233770  1.265416# print(df.T) # 轉置(Transposing)#    2018-01-16  2018-01-17  2018-01-18# A   -1.137015   -0.067200    0.737709# B   -1.141811    0.335953    1.023016# C    2.481266   -0.957599    0.011144# D    1.485434   -0.605588    0.592746# print(df)# print(df.sort_index(axis=1, ascending=False)) # axis=1 按照列名排序 axis=0 按照行名排序#                    A         B         C         D# 2018-01-16 -0.787226  0.321619  1.097938 -0.701082# 2018-01-17 -0.417257 -0.163390 -0.943166 -0.497475# 2018-01-18  0.486670 -0.733582  1.923475 -1.145891#                    D         C         B         A# 2018-01-16 -0.701082  1.097938  0.321619 -0.787226# 2018-01-17 -0.497475 -0.943166 -0.163390 -0.417257# 2018-01-18 -1.145891  1.923475 -0.733582  0.486670# print(df.sort_values(by=‘B‘))#                    A         B         C         D# 2018-01-17  0.817088 -0.792903  1.643429 -0.008784# 2018-01-18  0.540910  0.662119  0.190846 -0.960926# 2018-01-16  0.333727  1.196133 -0.527796  0.677337

 

Python 筆記 #13# Pandas: Viewing Data

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.