import pandas as pd
import json
dfs = pd.read_excel("工作表.xlsx", sheet_name=None)
def typecof(x):
if type(x) == str:
if ('{' in x):
try:
return json.loads(x)
except:
return
else:
return x
else:
return x
for df in dfs.values():
for col in df.columns:
df[col] = df[col].apply(lambda x: typecof(x))
def guolv(j):
if type(j) == dict:
if 'smr_reply' in j.keys():
if((('键','值') in j.items()) or (('键','值') in j.items())):
return j
else:
return
else:
return
else:
return j
for df in dfs.values():
for col in df.columns:
df[col] = df[col].apply(lambda x: guolv(x))
# 将多个sheet保存至同一个excel中
writer = pd.ExcelWriter('done_.xlsx')
for i in dfs.keys():
dfs[i].to_excel(writer,sheet_name = i,index=None)
writer.save()
标签:sheet,df,单元格,excel,dfs,return,col
From: https://www.cnblogs.com/tiansz/p/16824901.html