Pandas Series and DataFramesΒΆ
Series and DataFrames are the two foundational data structures in Pandas. A Series is a one-dimensional labeled array that can hold any data type, while a DataFrame is a two-dimensional table composed of multiple Series sharing the same index. Understanding how to create, inspect, and manipulate these structures is the first step in any Pandas workflow.
This notebook covers creating NumPy arrays from Python lists, constructing Series with custom indices, performing arithmetic between aligned Series (where Pandas automatically matches by index label and fills mismatches with NaN), and building DataFrames from both nested lists and dictionaries with explicit index and column labels.
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

