Advertisements
Advertisements
प्रश्न
Kabir, a data analyst, has stored the voter's name and age in a dictionary. Now, Kabir wants to create a list of dictionaries to store data of multiple voters. He also wants to create a DataFrame from the same list of dictionaries having appropriate row labels as shown below:
Voter_Name |
Voter_Age |
|
Ar1001 |
Arjun |
35 |
Ba3002 |
Bala |
23 |
Go4002 |
Govind |
25 |
Dh4007 |
Dhruv |
19 |
Na6005 |
Navya |
18 |
Help Kabir in writing a Python program to complete the task.
कोड लेखन
उत्तर
import pandas as pd
# Data of multiple voters as a list of dictionaries voters _data = [
{'Voter _Name': 'Arjun', 'Voter _Age': 35},
{' Voter_Name': 'Bala', ' Voter_Age': 23},
{' Voter_Name': 'Govind', 'Voter_Age': 25},
{' Voter _Name': 'Dhruv', ' Voter _Age': 19},
{' Voter_ Name': 'Navya', ' Voter_ Age': 18},
]
# Create a DataFrame from the list of dictionaries
df = pd.DataFrame(voters_data, index=['Ar1001', 'Ba3002',
'Go4002', 'Dh4007', 'Na6005'])
# Display the DataFrame
print(df)
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2023-2024 (February) Set 4