0

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:

enter image description here

and this is what I am looking for:

enter image description here

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?

1
  • I've read your file as csv and df.to_excel('test.xlsx', index=False) gave me the result which you are looking for. Commented Feb 25, 2020 at 14:50

1 Answer 1

4

You have overthought the problem:

df = pd.read_csv(excel, sep=',')
df.to_excel('output.xlsx', index=False)

is enough...

Sign up to request clarification or add additional context in comments.

1 Comment

Oh lord... It was actually that simple.. Oh wlel.! Thanks! :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.