python处理Excel文件
手动处理太麻烦,帮别人写的代码处理。
import pandas as pd
def handle():
df = pd.read_excel('/Users/shaopengyang/Downloads/lemon.xlsx', dtype={'品牌':str, '省':str, '市':str, '院':str, '料号':str, '产生时间':str})
# df2 = pd.ExcelFile('/Users/shaopengyang/Downloads/lemon.xlsx')
# 这个会直接默认读取到这个Excel的第一个表单
print("获取到所有的值:\n{0}".format(df.columns)) # 格式化输出
df2 = pd.DataFrame()
cnt = 1
i = 0
for i in df.index:
liaonum = df['料号'].at[i]
liaonum = liaonum.strip()
liaonums = liaonum.split('、')
j = 0
while j < len(liaonums):
curS = {'品牌':df['品牌'].at[i], '省':df['省'].at[i], '市':df['市'].at[i], '院':df['院'].at[i],
'料号':liaonums[j], '产生时间':df['产生时间'].at[i] }
s1 = pd.Series(curS, name="xxx")
df2 = df2.append(s1)
j+=1
i+=1
df2.to_excel('/Users/shaopengyang/Downloads/huahua.xlsx')
if __name__ == '__main__':
handle()

浙公网安备 33010602011771号