panddas 读入 csv 文件¶
In [9]:
import pandas as pd
f = open('D:/Project/180414山东癌症交接/初始数据/1973to2015.csv')
all_data = pd.read_csv(f)
In [30]:
df2014 = all_data[(all_data['year'] == 2014) & (all_data['sex'] == '合计')]
In [31]:
df2014.rename(columns={ 'cu': 'cu2014', 'norm': 'norm2014'}, inplace=True)
In [32]:
df2005 = all_data[(all_data['year'] == 2005)& (all_data['sex'] == '合计')]
df2005.rename(columns={ 'cu': 'cu2005', 'norm': 'norm2005'}, inplace=True)
In [38]:
me_data = pd.merge(df2014,df2005,how='inner',on='code')
In [39]:
me_data = pd.merge(me_data,df2014,how='inner',on='code')
In [42]:
norm = me_data[['code','norm1975','norm1992','norm2005','norm2014']]
cu = me_data[['code','cu1975','cu1992','cu2005','cu2014']]
In [46]:
norm.to_csv("D:/Project/norm.csv")
In [47]:
cu.to_csv("D:/Project/cu.csv")