Hi, Folks hope you all are doing awesome, So today I’m going to start Data analysis with Python Pandas. this tutorial is all about the Basics of Data analysis. we are going to read CSV file with the help of Pandas library.
Pandas is one of the most popular Python libraries for Data Science and Analytics. I like to say it’s the “SQL of Python.” Why? Because pandas help you to manage two-dimensional data tables in Python. Of course, it has many more features. In this pandas tutorial series, I’ll show you the most important things that you have to know as an Analyst or a Data Scientist.
I assume that you already install Python in your System, So I’m going to start directly with Pandas. In order to use pandas, we need an IDE you can use PyCharm or Jupyter notebook either one of them.
In order to run the Pandas Code, we have to import the Pandas Library to support all its features.
import pandas as pd
“pd” works as an alias to access the panda’s libraries. Now Pandas is ready to execute the essential code
In the second step, we have to define a variable which holds the data of CSV file and that variable we called data frame.
df = pd.read_csv("D:\employee.csv")
pd refer the Pandas library to read CSV file and inside it, we call the file location.
After that, we are going to display that our code is working or not and for that part, we are going to use head() function. Head function print 5 first value as the default mode.
df is our data frame, so we called data from CSV file with pandas.
All code Together
import pandas as pd df = pd.read_csv("D:\employee.csv") df.head() Output ID Name Department 0 1 Rohan IT 1 2 Mohan HR 2 3 Ram Marketing 3 4 Abhishek IT 4 5 Jamaley IT
If you want to sort the data by the department with Pandas then it is very easy. just add index_col=’Department’ after your file location.
df = pd.read_csv("D:\employee.csv", index_col='Department')
Here is the sorted data.
ID Name Department IT 1 Rohan HR 2 Mohan Marketing 3 Ram IT 4 Abhishek IT 5 Jamaley
Here are the Screenshots : –
Before sorting the data
After sorting the data with index_col
Check Python Python Libraries for Data Science
I hope this post helped you to know Data Science – First Step with Python and Pandas (Read CSV File). To get the latest news and updates follow us on twitter & facebook, subscribe to our YouTube channel. And If you have any query then please let us know by using the comment form.
Kunal Aneja says
Data Science has come out as a big thing from past few years and will continue to do so. Check out future Data Science trends here –