Python question

User Generated

OEFNETVnetvnetvoef

Programming

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

User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

At...


Anonymous
Excellent! Definitely coming back for more study materials.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags