What is Pandas?

404 image

Importing pandas

import pandas as pd

Reading in Data

candy = pd.read_csv('data/candybars.csv')


candy
name weight chocolate peanuts caramel available_canada_america
0 Coffee Crisp 50 1 0 0 Canada
1 Butterfinger 184 1 1 1 America
2 Skor 39 1 0 1 Both
... ... ... ... ... ... ...
22 Almond Joy 46 1 0 0 America
23 Oh Henry 51 1 1 1 Both
24 Cookies and Cream 43 0 0 0 Both

25 rows × 6 columns

candy.columns
Index(['name', 'weight', 'chocolate', 'peanuts', 'caramel', 'available_canada_america'], dtype='object')


candy.shape
(25, 6)
candy.head(2)
name weight chocolate peanuts caramel available_canada_america
0 Coffee Crisp 50 1 0 0 Canada
1 Butterfinger 184 1 1 1 America


candy.head()
name weight chocolate peanuts caramel available_canada_america
0 Coffee Crisp 50 1 0 0 Canada
1 Butterfinger 184 1 1 1 America
2 Skor 39 1 0 1 Both
3 Smarties 45 1 0 0 Canada
4 Twix 58 1 0 1 Both

Functions/Methods and Attributes

404 image

Attributes

Take candy.shape as an example.

In this case, our dataframe candy is our object and .shape is the attribute describing it.


Functions

In the example of pd.read_csv(), this function does the action of reading in our data.

Comments

# This line does not execute anything. 


candy.shape  # This will output the shape of the dataframe

Let’s apply what we learned!