import pandas as pd
left = pd.DataFrame({'key':['K1','K2','K3','K4'],'A':['A1','A2','A3','A4'],'B':['B1','B2','B3','B4']})
right = pd.DataFrame({'key':['K1','K2','K3','K4'],'C':['C1','C2','C3','C4'],'D':['D1','D2','D3','D4']})
left
right
pd.merge(left,right,on='key')#以key为键
left = pd.DataFrame({'key1':['K1','K2','K3','K4'],'key2':['K1','K2','K3','K4'],'A':['A1','A2','A3','A4'],'B':['B1','B2','B3','B4']})
right = pd.DataFrame({'key1':['K1','K2','K3','K4'],'key2':['K1','K2','K3','K5'],'C':['C1','C2','C3','C4'],'D':['D1','D2','D3','D4']})
pd.merge(left,right,on='key1')#以key1为键
import pandas as pd
pd.get_option('display.max_rows')#60
pd.set_option('display.max_rows',100)
pd.Series(index=range(20))'''
0 NaN
1 NaN
2 NaN
3 NaN
4 NaN
5 NaN
6 NaN
7 NaN
8 NaN
9 NaN
10 NaN
11 NaN
12 NaN
13 NaN
14 NaN
15 NaN
16 NaN
17 NaN
18 NaN
19 NaN
dtype: float64
'''
pd.get_option('display.max_columns')#20
pd.set_option('display.max_columns',30)
pd.DataFrame(columns=range(0,30))# 0 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
pd.get_option('display.max_colwidth')#字符串长度#50
pd.set_option('display.max_colwidth',100)
pd.Series(index=['A'],data=['t'*70])'''
A tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt
dtype: object
'''
pd.get_option('display.precision')#小数点后几位#6
pd.set_option('display.precision',5)#小数点后几位
pd.Series(data=1.143567888976)'''
0 1.14357
dtype: float64
'''
数据透视表
import pandas as pd
example = pd.DataFrame({'Month':["January","January","January","January","February","February","February","February","March","March","March","March"],'Category':["Transportation","Grocery","Household","Entertainment","Transportation","Grocery","Household","Entertainment","Transportation","Grocery","Household","Entertainment"],'Amount':[74.,235.,175.,100.,115.,240.,225.,125.,90.,260.,200.,120.]})
Day 3Pandas基本操作titanic数据集: 密码:pje4merge操作import pandas as pdleft = pd.DataFrame({'key':['K1','K2','K3','K4'], 'A':['A1','A2','A3','A4'], 'B':['B1','B2','B3...