Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)

Can anyone tell me how to read the CSV file in Python?

1 Answer

0 votes
by (108k points)

For reading any CSV file, first of all, you have to import the Pandas package. So, you can write:

import pandas as pd

Then, you have to copy the path of the CSV file. Let’s say, the path of the file is C:\Users\Lenovo\Desktop\customer_churn.csv

Now, in Jupyter Notebook, write:

data=pd.read_csv(‘C:\Users\Lenovo\Desktop\customer_churn.csv’)

Then, in the path, change the backward slashes to double back-slashes as shown below:

data=pf.read_csv(‘C:\\Users\\Lenovo\\Desktop\\customer_churn.csv’)

With the help of the above syntax, your customer_churn.csv file will get imported into the data variable. Now, if you want to see your DataFrame, then simply execute the following: 

data.head()

This way, you will be able to see the top five records from the DataFrame.

If you are looking for an online course to learn Python, check out this Python Course by Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Dec 24, 2020 in Python by ashely (50.2k points)
0 votes
1 answer

Browse Categories

...