Pandas Series and DataFramesΒΆ
Series and DataFrames are the two core data structures in Pandas. A Series is a one-dimensional labeled array (similar to a column in a spreadsheet), while a DataFrame is a two-dimensional labeled data structure (similar to a table). Every DataFrame is composed of multiple Series objects sharing the same index.
This notebook covers creating NumPy arrays and Pandas Series from Python lists, adding custom index labels to a Series, performing arithmetic between Series with automatic index alignment, and constructing DataFrames from both nested lists and dictionaries. Understanding these building blocks is essential because every Pandas operation β filtering, grouping, merging, and visualization β operates on Series and DataFrames.
import pandas as pd
import numpy as np
my_list = [10,25,35]
x = np.array(my_list)
print(x)
type(x)
pd.Series(my_list)
type(y)
index_values = ['Best','Second Best','Third Best']
my_list = [10,25,35]
one = pd.Series(data=my_list,index=index_values)
index_values = ['Best','Second Best','Forth Best']
my_list = [10,25,40]
two = pd.Series(data=my_list,index=index_values)
total = one + two
total
type(total)
ice_cream = [['MCC',1],['Butterscotch',2],['Butter Pecan',3]]
ice_cream_dataframe = pd.DataFrame(ice_cream,index=['Flavor 1','Flavor 2','Flavor 3'], columns=('Flavor','Scoops'))
ice_cream_dataframe
type(ice_cream_dataframe)
ice_cream = ['MCC','Butterscotch','Butter Pecan']
scoops = [1,2,3]
dataframe_icecream = {'Flavor': ice_cream, 'Scoops': scoops}
ice_cream_dataframe = pd.DataFrame(dataframe_icecream,index=['Flavor 1','Flavor 2','Flavor 3'] )
ice_cream_dataframe

