【发布时间】:2021-03-18 12:52:02
【问题描述】:
Helo 任何人都可以帮助我读取和导出多个文件。我有客户数据的每日档案。如何自动读取所有文件:
import pandas
with open("Customers_1oct.txt", "r") as file:
data = file.read()
df = pandas.DataFrame(
[
{
"Detail Indicator": line[0:2].strip(),
"Name": line[2:102].strip(),
"Ref No": line[182:232].strip(),
"Ind": line[232:234].strip(),
"Amount": line[234:249].strip(),
}
for line in data.splitlines()
if len(line) > 1
]
)
df
我也想导出成多个文件,怎么办?
datatoexcel = pandas.ExcelWriter('1oct.xlsx')
df.to_excel(datatoexcel)
print('DataFrame is written to Excel File successfully.')
【问题讨论】:
-
您想以哪种方式导出到多个文件中?
标签: python pandas numpy operating-system glob