我试着跟随如何将txt文件转换为excel文件 https://stackoverflow.com/questions/59946452/how-to-convert-txt-to-excel-file然而问题似乎仍然是在第一列写了一个起始ID,但我真的不想这么做。现在看起来像:
这就是我正在寻找的:
我所做的是编写了一个读取 txt 文件的代码,如下所示:
id,quanitity,bu,link
80379173,1000.0,045,https://helloworld.com/-80379173/
10290396,1000.0,045,https://helloworld.com/-10290396/
40379170,1000.0,045,https://helloworld.com/-40379170/
20379171,1000.0,045,https://helloworld.com/-20379171/
通过代码:
将 pandas 导入为 pd
excel = 'Available-Online-ART.txt'
df = pd.read_csv(excel, sep=',')
column_indexes = list(df.columns)
df.reset_index(inplace=True)
df.drop(columns=df.columns[-1], inplace=True)
column_indexes = dict(zip(list(df.columns), column_indexes))
df.rename(columns=column_indexes, inplace=True)
df.to_excel('output.xlsx', 'Sheet1', index=False)
但似乎它仍然添加了第一列,但也删除了最后的链接。我想知道如何才能使它像第二张图片一样工作?