Pandas Basics # Python

Python 3 comes with different libraries and they offer some really cool references. One of them is Pandas. It is an open source, BSD licenced library providing which provides high performance, easy to use data structures and data analysis for the Python programming language.  Let us now try to understand one of the codes that have been used by codeacademy to understand how pandas work in real time.

import pandas as pd # This line is used to import the pandas library into your code.

# Load data
df = pd.read_csv(‘page_visits.csv’) # This function is used to do read csv files and do operations on it. Not only does it makes it easier to open CSV files through it, it also helps to do various other operations quite easily. There are several parameters that this library provides the users with. For now, let us go with the ones that we will be using in the code.

# Display data
print(df.head()) # Here, df is the pointer that points to the csv file that has been read by the panda.

# Display survey results
print(
df.groupby(‘website_goal’)\
.first_name.count()\
.reset_index()\
.rename(columns={‘first_name’: ‘number_of_citizens’})
)

# Here group by, works the same way it does in any other SQL.

Happy Learning 🙂



Leave a comment