How to Load different types of files in Jupyter(Python)| Python tool Data science

 
Working with data from files in data science(using python)| |Jupyter notebook
How to load different types of file format in jupyter?
We can load file in python by using pandas library in jupyter notebook.
We have different types of file formats in data science like.csv,.txt,.xlsx,json etc….you already know about these different types of file if you are working with data.
Firstly I will tell you in which file formats we are loading data in jupyter. Let’s show you in ipython.
You get a list of files and file name that are there in current directory.
 
Syntax
importos
os.listdir()
So that, there is no need to go back and check the file name.
I will start loading all these files.
We need to import pandas library.
Syntax-
import pandas
Working with csv files-
Syntax-
Student_Details=pandas.read_csv(“Student_Details.csv”)
Student_Details
Student_Details is data frame.
read_csv is a method
Student_Details.csv is the name of the csv file that we want to open in jupyter.
Now, we can see csv files open in ipython.
 
Working with json files –
Syntax-
Student_Details=pandas.read_json(“Student_Details.json”)
Student_Details
Student_Details.json is the name of the json file that we want to open in jupyter.
Now, we can see json files open in ipython.
Working with Txt file-
Syntax-
Student_Details=pandas.read_csv(“Student_Details.txt”)
Student_Details
Student_Details.txt is the name of the text file that we want to open in jupyter.
If you are using comma(,)  separators in file then you can use read_csv.
Working with Txt file with any separators-
Syntax-
Student_Details=pandas.read_csv(“Student_Details_separator.txt” ,sep=”|”)
Student_Details
Student_Details_separator.txt is the name of the text file with pipes(|) separator that we want to open in jupyter.
Working with Excel file-
Excel file have multiple sheets inside them. You need to define sheet name by using index name. If you want to use first sheet you need to pass 0, if second sheet then pass 1…..
Syntax-
Student_Details=pandas.read_excel(“Student_Details.xlsx”, sheet_name=0)
Student_Details
Student_Details.xlsx is the name of the excel file that we want to open in jupyter.
Now, we can see excel files in python.
When you have loaded data in python you can perform many operations like add columns, delete columns, merge columns etc.., and also you can do data analysis with the help of jupyter notebook.
I hope you understood loading of different files format in jupyter notebook. You will learn many things in new articles. Keep reading.
If you have any doubt please comment here…
Thank you…Happy coding!!

Leave a Reply

Your email address will not be published. Required fields are marked *