import pandas as pd

This is a quick introduction to Pandas. pandas is an open source, BSD-licensed library providing high-performance, easy-to-use data structures and data analysis tools for the Python programming.
Using pandas you can convert your data into an excel like format and the manipulate that data in many ways. The keyword Dataframe is like an excel spreadsheet that has all your data.

Watch the following video to get started:

Reading Csv’s

Reading csv’s is quite simple
glassdata = pd.read_csv('glass.csv')

Some csv’s are seperated by other characters for example a tab space, to tackle that we use
glassdata = pd.read_csv('glass.csv',sep='t')

data.head()

The data.head() will give the first 5 rows of your data.

data.sort()

Sort the data in ascending according to a given column
data_sorted = data.sort(["AGE"])

Sql like filter conditions

Filter out data in your dataframe,for instance, we want a list of all females who are not graduate and got a car. To find this out we use the following code:
You can also use loc and iloc to perform just about any data selection operation. loc is label-based, which means that you have to specify rows and columns based on their row and column labels. iloc is integer index based, so you have to specify rows and columns by their integer index
data.loc[(data["Gender"]=="Female") & (data["Education"]=="Not Graduate") & (data["Car_Status"]=="Y"), ["Gender","Education","Car_Status"]]

As you can see, the conditions above greatly resemble that of your SQL queries.

Merging Dataframes

Merging dataframes becomes essential when information from different sources needs be taken as 1 inorder for it to make sense,
data_merged = data.merge(right=data1, how='inner',left_on='data2',right_index=True, sort=False)

Looping through the rows

for i,column in data.iteritems(): print(column)

Indexing dataframes

Indexing can be done normaly using [] brackets.
cars['year']

Plotting data to a Graph

glassdata.plot() plt.show()

And a lot more:

https://www.hackerearth.com/practice/machine-learning/data-manipulation-visualisation-r-python/tutorial-data-manipulation-numpy-pandas-python/tutorial/
visit the above link to learn more about the pandas framework.

Leave a reply:

Your email address will not be published.

Site Footer

Sliding Sidebar

About Me

About Me

Hey, I am Thomas Ashish Cherian. What I cannot create, I do not understand.

Social Profiles