Python-dataframe操作

2019-04-16  本文已影响0人  微雨旧时歌丶
df=df.replace({'name':s},alt_name) # 'name'就是df中的‘name’列,将字符串s替换为字符串alt_name,单元格匹配
df = pd.DataFrame(list(dict_FileCountry.items()), columns=['fileName', 'country'])
df_locations = pd.read_csv('locations.csv',dtype = 'str')
dict_locations = df_locations.set_index('name').T.to_dict() # 转化为字典
countries_GDP = dict(zip(df_GDP['Country Name'],df_GDP[2018]))
# 读时区信息
utc = pd.read_excel('AssistData/timezone.xls')
dict_utc = utc.set_index('Country').T.to_dict('list')
utc = {}
for k in dict_utc:
    utc[k] = dict_utc[k][0]
dict_utc = utc
df = pd.read_excel(in_file,dtype = 'str')
a=df.values # 矩阵形式,[行][列],或者[行,列] 从0开始
# 取一列: a[:,j]
# 取一行:a[i]
nrows = a.shape[0] #行数
ncols = a.shape[1] # 列数
df_new = pd.DataFrame(a) # 变回dataframe
上一篇下一篇

猜你喜欢

热点阅读