Google News
logo
Pandas - Interview Questions
How to create Data Frame in Pandas?
Data Frame in Pandas can be created either directly from a dictionary or by combining various series.
 
import pandas as pd
country_population = {'India': 1600000000, 'China': 1730000000, 'USA': 390000000, 'UK': 450000000}
population = pd.Series(country_population)
#print(population)

country_land = {'India': '2547869 hectares', 'China': '9543578 hectares', 'USA': '5874658 hectares',  'UK': '6354652 hectares'}
area = pd.Series(country_land)
#print(area)

df = pd.DataFrame({'Population': population, 'SpaceOccupied': area})
print(df)
 
Output :
 
             Population      SpaceOccupied
India     1600000000    2547869 hectares
China    1730000000    9543578 hectares
USA        390000000    5874658 hectares
UK          450000000    6354652 hectares
 
Advertisement