Export table (in pd.Dataframe) to csv - Python format

Asked

Viewed 4,274 times

1

are fine?

How to export or save a table made with pandas.Dataframe in csv or xlsx format in Python?

2 answers

2

export csv

df = pd.DataFrame({'name': ['Raphael', 'Donatello'],
                   'mask': ['red', 'purple'],
                   'weapon': ['sai', 'bo staff']})
csv = df.to_csv(index=False)

export in xlsx

df1 = pd.DataFrame([['a', 'b'], ['c', 'd']],columns=['col 1', 'col 2'])
df1.to_excel("output.xlsx") 
  • thank you very much :)

1

Example of Pandas.Dataframe documentation:

 writer = pd.ExcelWriter('output.xlsx')
 df1.to_excel(writer,'Sheet1')
 df2.to_excel(writer,'Sheet2')
 writer.save()

Documentation Panda

  • thank you very much :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.