Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)
Can anyone tell me how to import the CSV file in Python?

1 Answer

0 votes
by (108k points)

For importing 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, you need to write this and paste the path as shown below:

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

Then, in the path, change the single 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 you can 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, I recommend this Python Certification program by Intellipaat.

Related questions

0 votes
2 answers
asked Sep 17, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Apr 9, 2020 in BI by Anup (1.6k points)
0 votes
1 answer
asked Jan 7, 2021 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Jul 20, 2019 in Data Science by sourav (17.6k points)

Browse Categories

...