一个名为err_code.xlsx的文件,打开里面内容是:
一共有几百行这样的数据。
我们的需求是将其变为这种字典格式,key、value、和注释:
可以借助pandas模块来进行。
脚本如下:
import pandas as pd df = pd.read_excel('err_code.xlsx') countrymap=dict(zip(df['APDU'],df['SW'])) Description = df['Description'] res = list(Description) list1 = [] for k, v in countrymap.items(): res = "'" + k + "'" + ':' "'" + v[2:] + "'" + "," + ' # ' list1.append(res) result = list(zip(list1, Description)) print(result) for i in result: i = str(i).replace('"', '').replace('(','').replace(')', '') print(i)
标签:Description,df,list1,excel,文档,result,res,pandas From: https://www.cnblogs.com/weixinyu98/p/17787111.html