Pandas is the most popular python library that is used for data analysis. It provides highly optimized performance with back-end source code is purely written in C or Python.
Way to analyse pandas in python:
Pandas dataframes: Pandas DataFrame is two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns). A Data frame is a two-dimensional data structure, i.e., data is aligned in a tabular fashion in rows and columns. Pandas DataFrame consists of three principal components, the data, rows, and columns.
Here we understand it easily by below some examples:
Importing csv file:
We import Contrib_data.csv by using read_csv().
Select column from csv file
Selecting row from csv file:
Selecting a single row from the csv file:
Data framing using loc and iloc:
Dataframe using iloc:
data.iloc # first row of data frame (Aleshia Tomkiewicz)
- Note a Series data type output.
data.iloc # second row of data frame (Evan Zigomalas)
data.iloc[-1] # last row of data frame (Mi Richan)# Columns:
data.iloc[:,0] # first column of data frame (first_name)
data.iloc[:,1] # second column of data frame (last_name)
data.iloc[:,-1] # last column of data frame (id)
Multiple row and column selections using iloc and DataFrame
data.iloc[0:5] # first five rows of dataframe
data.iloc[:, 0:2] # first two columns of data frame with all rows
data.iloc[[0,3,6,24], [0,5,6]] # 1st, 4th, 7th, 25th row + 1st 6th 7th columns.
data.iloc[0:5, 5:8] # first 5 rows and 5th, 6th, 7th columns of data frame
(county -> phone1).
Dataframe using loc:
The Pandas loc indexer can be used with DataFrames for two different use cases:
Selecting row by boolean
Selecting row by label
Select row by label:
Find all CAND_NAME whose name is WARREN,ELIZABETH
In next tutorial we discuss some complex example which is very useful for any Data Analyst.
If you like Codersarts blog and looking for Assignment help,Project help, Programming tutors help and suggestion you can send mail at firstname.lastname@example.org.
Please write your suggestion in comment section below if you find anything incorrect in this blog post.