1.读取Excel

1.1 读取文件时转换指定列

  1. import pandas as pd
  2. pd.read_excel("data.xlsx", usecols=[0, 1, 3, 5], names=["姓名", "年龄", "手机号", "地址"],
  3. converters={"手机号": str})

2. 写入Excel

2.1 写入多个Sheet

  1. import pandas as pd
  2. with pd.ExcelWriter("result.xlsx") as writer:
  3. for df in dfs:
  4. df.to_excel(writer, sheet_name=df["name"].unique()[0], index=False, encoding="utf8)