1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
import pandas as pd import string t1 = pd.Series(np.arange(10),index=list(string.ascii_uppercase[:10])) t2 = pd.Series({'name':'xiaoming'}) t3 = pd.Series([1,2,3,4,5])
t1[[1,2,3]] t1[['b','c','d']]
t1.index
t1.values
series.unique()
data = {'state': ['Ohio', 'Ohio', 'Ohio', 'Nevada', 'Nevada', 'Nevada'], 'year': [2000, 2001, 2002, 2001, 2002, 2003], 'pop': [1.5, 1.7, 3.6, 2.4, 2.9, 3.2]} frame = pd.DataFrame(data, columns=['year','pop','state'],index=[1,2,3,4,5,6]) frame['year'].name frame.loc[1] del frame['pop']
df = df.reindex(['a','b','c','d','e']) df = df.reindex(columns=[], fill_values=0)
obj3 = pd.Series(['blue', 'purple', 'yellow'], index=[0, 2, 4]) obj3.reindex(np.arange(5),method='ffill')
df = df.drop([1,2])
df = df.drop([''], axis=1)
df[df['three'] > 5] df.loc[['row_index'],['col_index']]
df.sort_index() series.sort_values() df.sort_index(axis=1) df.sort_values(by=['col1','col2'])
df.shape df.dtypes df.ndim df.index df.columns df.values df.head(3) df.tail(3)
df=pd.read_csv('.csv')
df.iloc[1,:]
df.fillna(0)
df["list_index"].median()
data['Title'] data.Title
df.apply(lambda x: (x - x.mean())/x.std())
df = pd.get_dummies(df, dummy_na=True)
c=pd.concat([a,b],axis=1) a,b是series或者dataframe类型
|