Python question

Python question

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_x000D_
0      ES      1_x000D_
1      IT      2_x000D_
2      US      3_x000D_
3      FR      4_x000D_
4      NL      5_x000D_
  country  value_x000D_
0      ES      1_x000D_
1      IT      2_x000D_
2      US      3_x000D_
3      FR      4_x000D_
4      NL      5_x000D_
  country  value_x000D_
0      ES      1_x000D_
1      IT      2_x000D_
2      US      3_x000D_
3      FR      4_x000D_
4      NL      5_x000D_
  country  value_x000D_
0      ES      1_x000D_
1      IT      2_x000D_
2      US      3_x000D_
3      FR      4_x000D_
4      NL      5_x000D_
  country  value_x000D_
0      ES      1_x000D_
1      IT      2_x000D_
2      US      3_x000D_
3      FR      4_x000D_
4      NL      5_x000D_
_x000D_

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_x000D_
0      ES      1_x000D_
1      IT      2_x000D_
2      US      3_x000D_
3      FR      4_x000D_
4      NL      5_x000D_
 _x000D_
0      ES      1_x000D_
1      IT      2_x000D_
2      US      3_x000D_
3      FR      4_x000D_
4      NL      5_x000D_
  _x000D_
0      ES      1_x000D_
1      IT      2_x000D_
2      US      3_x000D_
3      FR      4_x000D_
4      NL      5_x000D_
  _x000D_
0      ES      1_x000D_
1      IT      2_x000D_
2      US      3_x000D_
3      FR      4_x000D_
4      NL      5_x000D_
  _x000D_
0      ES      1_x000D_
1      IT      2_x000D_
2      US      3_x000D_
3      FR      4_x000D_
4      NL      5

"You need a similar assignment done from scratch? Our qualified writers will help you with a guaranteed AI-free & plagiarism-free A+ quality paper, Confidentiality, Timely delivery & Livechat/phone Support.


Discount Code: CIPD30



Click ORDER NOW..

order custom paper