Friday, 31 January 2020

How to write a csv file in python?

# This is tested on Jupytor Notebook.
# Note: Ensure the data frame name is df which is loaded into your python notebook. 

# Importing the packages
import pandas as pd

# Write to file
def write_file(df):       
    df.to_csv('df_results.csv',index = False)

# Calling the method
df = write_file(df)

# This write the results of df into file name df_results.csv

1 comment:

  1. Dear Readers,
    Please share your comments here. I am glad to help you.
    Regards,
    Nages.

    ReplyDelete