Read a CSV File into Python


You can read (import) a comma separated values file (.CSV) into Python easily. We’ll be using pandas for this because we want to read the file into a DataFrame.

Suppose your file is called friends.csv and it is stored in the test folder in your D drive of your Windows computer. The data file is stored on the D drive under the Test folder.

# A simple example of reading in a CSV file into Python
import pandas as pd
df = pd.read_csv(r'D:\MyData\Test\friends.csv')
df

In Jupyter Notebook, it looks like the following.

Below is what the original file looks like in Notepad++.

Leave a Reply