Firstly the import for the panda library is as following :
import pandas as pd
Series through the panda library will allow us to do additional things. Panda series might look like numpy or normal arrays , however, they are similar to python Dict.
g7_pop = pd.series([35.467, 63.951, 80.940, 60.665, 127.061, 64.511, 318.523])
#Population in millions
g7_pop.name = 'G7 population in millions'
Similarly to numpy arrays, we can also treat series the same by checking the type, the values, and the type
g7_pop.dtype #gets the data type of the series
g7_pop.values #Showcases the values
type(g7_pop.values) #Shows whether its an array etc
A series has an index, which is similar to the automatic index assigned to python list. WE can think of this as a dictionary as each value has an index we can address.
g7_pop[0] etc etc
However, in contrast to lists, we can explicitly define the indexes ourself. Because of this, we can say that the series looks like “Ordered Dictionaries”
g7_pop.index = [
'Canada',
'France',
'Germany',
'Italy',
'Japan',
'United Kingdom',
'United States',
]
We can also create series out of dictionaries
pd.Series({
'Canada': 35.467,
'France': 63.951,
'Germany': 80.94,
'Italy': 60.665,
'Japan': 127.061,
'United Kingdom': 64.511,
'United States': 318.523
}, name='G7 Population in millions')
Indexing works very similarly to how lists and dictionaries apply and use them. You can use the index of the element you're looking for
g7_pop['Canada']
#numeric positions can also be used through iloc
g7_pop.iloc[0]
#You can also select multiple items at once
g7_pop[['Canada', 'France']]
#Slicing in pandas
g7_pop['Canada' : 'Italy']