Description
I have the folowing piece of python code (in Jupyter notebook):
import numpy as np
import pandas as pd
my_list = ["A", "B", "C","D" ,"E"]
for i in my_list:
d = {'value': [1,2,3,4,5],'country': ['ES','IT','US','FR','NL']}
df = pd.DataFrame(data=d)
print(df)
The output is:
country value 0 ES 1 1 IT 2 2 US 3 3 FR 4 4 NL 5 country value 0 ES 1 1 IT 2 2 US 3 3 FR 4 4 NL 5 country value 0 ES 1 1 IT 2 2 US 3 3 FR 4 4 NL 5 country value 0 ES 1 1 IT 2 2 US 3 3 FR 4 4 NL 5 country value 0 ES 1 1 IT 2 2 US 3 3 FR 4 4 NL 5
I want to write this output in excel csv file using the command : df.to_csv("filename.csv" , index = False).
Where should I put this command in order to get an excel document as the output of my code?
In particular, I would prefer to get the column names "country" and "value" only once on the top of my excel document. Therefore the csv file should be like this:
country value 0 ES 1 1 IT 2 2 US 3 3 FR 4 4 NL 5 0 ES 1 1 IT 2 2 US 3 3 FR 4 4 NL 5 0 ES 1 1 IT 2 2 US 3 3 FR 4 4 NL 5 0 ES 1 1 IT 2 2 US 3 3 FR 4 4 NL 5 0 ES 1 1 IT 2 2 US 3 3 FR 4 4 NL 5
Explanation & Answer
Review
Review
24/7 Homework Help
Stuck on a homework question? Our verified tutors can answer all questions, from basic math to advanced rocket science!
Similar Content
Related Tags
The Metamorphosis
by Franz Kafka
A Farewell To Arms
by Ernest Hemingway
The House of the Seven Gables
by Nathaniel Hawthorne
Wuthering Heights
by Emily Brontë
My Brilliant Friend
by Elena Ferrante
Into Thin Air
by Jon Krakauer
Rules Of Civility
by Amor Towles
Steppenwolf
by Hermann Hesse
The Point of it All - A Lifetime of Great Loves and Endeavors
by Charles Krauthammer