How to save as CSV file in Python using Pandas

1 min

As said previously, CSV files are another industry standard.

Widely used when dealing with structured data shaped in DataFrame like structure.

Saving our csv file

df = pd.DataFrame({"firstname" : ['George', 'Aman', 'Dennis', 'John', 'Foe'], "lastname": ['Dubois', 'Van Hein', 'Washington', 'Doe', 'Less']})
We define our example DataFrame

Now that we have our DataFrame ready

df.to_csv("path/to/file.csv")
We save the DataFrame as CSV using to_csv Pandas method

Here you are ! You know now how to save files as CSV in Python.

How to read a CSV file in Python

You might want to check the other article I wrote on how to read a csv file in Python using Pandas.

How to read a CSV file in Python using Pandas
The simplest way to read csv file in Python.Using the pandas library we can transform the csv into a workable dataframe object that looks just like an excel sheet.