Answers for "pyhton output to a csv file"

20

csv to python

import pandas as pd

df = pd.read_csv (r'Path where the CSV file is stored\File name.csv')
print (df)
Posted by: Guest on April-15-2020
2

python writing to csv file

import csv  

header = ['name', 'area', 'country_code2', 'country_code3']
data = ['Afghanistan', 652090, 'AF', 'AFG']

with open('countries.csv', 'w', encoding='UTF8') as f:
    writer = csv.writer(f)

    # write the header
    writer.writerow(header)

    # write the data
    writer.writerow(data)
Posted by: Guest on December-21-2021

Python Answers by Framework

Browse Popular Code Answers by Language