English

Write a Python program to create the following DataFrame using a Dictionary of Series: City State 0 Mumbai Maharashtra 1 Dehradun Uttarakhand 2 Bengaluru Karnataka 3 Hyderabad Telangana - Informatics Practices

Advertisements
Advertisements

Question

Write a Python program to create the following DataFrame using a Dictionary of Series:

  City State
0 Mumbai Maharashtra
1 Dehradun Uttarakhand
2 Bengaluru Karnataka
3 Hyderabad Telangana
Code Writing
Advertisements

Solution

import pandas as pd
city_series = pd.Series(["Mumbai", "Dehradun", "Bengaluru", "Hyderabad"])
state_series =
pd.Series(["Maharashtra", "Uttarakhand", "Karnataka", "Telangana"]) 
data = {"City": city _series, "State": state series}
df = pd.DataFrame(data)
print(df)
shaalaa.com
  Is there an error in this question or solution?
2024-2025 (March) Set 4

APPEARS IN

Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×