Pandas基礎用法合集(中文官檔)
- 2019 年 11 月 27 日
- 筆記
本節介紹 pandas 數據結構的基礎用法。下列程式碼創建示例數據對象:
In [1]: index = pd.date_range('1/1/2000', periods=8) In [2]: s = pd.Series(np.random.randn(5), index=['a', 'b', 'c', 'd', 'e']) In [3]: df = pd.DataFrame(np.random.randn(8, 3), index=index, ...: columns=['A', 'B', 'C']) ...:
Head 與 Tail
head()
與 tail()
用於快速預覽 Series 與 DataFrame,默認顯示 5 條數據,也可以指定要顯示的數量。
In [4]: long_series = pd.Series(np.random.randn(1000)) In [5]: long_series.head() Out[5]: 0 -1.157892 1