import pandas as pd import numpy as np ''' s = pd.Series([1,3,6,np.nan,44,1]) print(s) 0 1.0 1 3.0 2 6.0 3 NaN 4 44.0 5 1.0 dtype: float64 ''' ''' dates = pd.date_range('20160101',periods=6) df = pd.DataFrame(np.random.randn(6,4),index=dates,columns=['a','b','c','d']) print(df) ''' dates = pd.date_range('20130101', periods=6) df = pd.DataFrame(np.arange(24).reshape((6,4)),index=dates, columns=['A','B','C','D']) print(df) print('-------------') print(df.A) #print(da['A']) print('-------------') print(df[0:3]) #print(df['20130101':'20130104']) #Data selection #pure tag filter print(df.loc['20130102']) #Select the line of data 20130102 print(df.loc[:,['A','B']]) #Select: all rows AB and two columns print(df.loc['20130102',['A','B']]) #pure number filter print(df.iloc[3]) #Show the index is the third print(df.iloc[3,1]) #Display the second number in the third line (the subscript starts from 0) print(df.iloc[1:3,1:3]) #Slice display #mix filter print(df.ix[:3,['A','B']]) #0 to 3 rows AB and two columns # filter selection print(df[df.A>8]) #Select all rows whose column A is greater than 8
Pandas use
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=324603466&siteId=291194637
Recommended
Ranking