Creating Pandas DataFrame. The following shows how to create Pandas DataFrame of the Python Pandas module.
Importing Module:
import pandas as pd
import sys
Creating Data:
Code:
names = ['Bob','Jessica','Mary','John','Mel']
births = [968, 155, 77, 578, 973]
BabyData = list(zip(names, births))
BabyData
Output:
[('Bob', 968), ('Jessica', 155), ('Mary', 77), ('John', 578), ('Mel', 973)]
Making DataFrame:
Code:
df = pd.DataFrame(data = BabyData, columns=['Names', 'Births'])
df
Output:
Names | Births | |
---|---|---|
0 | Bob | 968 |
1 | Jessica | 155 |
2 | Mary | 77 |
3 | John | 578 |
4 | Mel | 97 |