| 123456789101112131415161718192021222324252627282930313233 |
- # View more python tutorials on my Youtube and Youku channel!!!
- # Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
- # Youku video tutorial: http://i.youku.com/pythontutorial
- """
- Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
- """
- from __future__ import print_function
- import pandas as pd
- import numpy as np
- s = pd.Series([1,3,6,np.nan,4,1]) # similar with 1D numpy
- print(s)
- dates = pd.date_range('20160101', periods=6)
- df = pd.DataFrame(np.random.randn(6,4), index=dates, columns=['A','B','C','D'])
- print(df['B'])
- df2 = pd.DataFrame({'A' : 1.,
- 'B' : pd.Timestamp('20130102'),
- 'C' : pd.Series(1,index=list(range(4)),dtype='float32'),
- 'D' : np.array([3] * 4,dtype='int32'),
- 'E' : pd.Categorical(["test","train","test","train"]),
- 'F' : 'foo'})
- print(df2)
- print(df2.dtypes)
- print(df.index)
- print(df.columns)
- print(df.values)
- print(df.describe())
- print(df.T)
- print(df.sort_index(axis=1, ascending=False))
- print(df.sort_values(by='B'))
|