I tried to follow How to convert txt to excel file however the problem seems to still be where it seems to write a start ID at the first column which I don't really want to. For now it looks like:
and this is what I am looking for:
What I have done is that I have written a code that read a txt file that looks like:
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/
by a code:
import pandas as 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)
but it seems like it still adds the first column but also removing the link at the end. I wonder how I can do it to make it works as the second picture?
You have overthought the problem:
df = pd.read_csv(excel, sep=',')
df.to_excel('output.xlsx', index=False)
is enough...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.