How to read csv/excel file in Jupyter notebook?
Ans: Every file has some location where it is stored, we call it a pathname. So for example,
you have downloaded iris.csv. Now, it is in the downloads folder, however if you want to
read it in a Jupyter notebook you have to specify the complete path. Below is the example
for your reference:
Step 1:
To get the path of the file, Right click on the file name as shown below:
Step 2:
Click Properties
Step 3:
Copy the path shown in front of location, & write filename with excel as shown below:
C:\Users\Downloads\iris.csv – this is the path of the file in my system.
However, in jupyter notebook we have to change the backslash to forward slash to read the
file, hence you have to write:
C:/Users/Downloads/iris.csv
Finally you have to write the below mentioned code:
Import pandas as pd
Iris=pd.read_csv(“C:/Users/Downloads/iris.csv”) # CSV file
Or
Iris_new=pd.read_excel(r’C:/Users/Downloads/iris.xlsx’) # Excel file