Informatics Practices
Sneha is writing a Python program to create a DataFrame using a list of dictionaries. However, her code contains some mistakes. Identify the errors, rewrite the correct code, and underline the corrections made.
import Pandas as pd
D1 = {'Name': 'Rakshit', 'Age': 25}
D2 = {'Name': 'Paul', 'Age': 30}
D3 = {'Name': 'Ayesha", 'Age': 28}
data = [D1, D2, D3)
df = pd.Dataframe(data)
print(df)
Python Pandas
2 Likes
Answer
import Pandas as pd # Error 1
D1 = {'Name': 'Rakshit', 'Age': 25}
D2 = {'Name': 'Paul', 'Age': 30}
D3 = {'Name': 'Ayesha", 'Age': 28} # Error 2
data = [D1, D2, D3) # Error 3
df = pd.Dataframe(data) # Error 4
print(df)
Error 1 — The module should be imported as import pandas as pd
(lowercase).
Error 2 — In D3
, the value has mismatched quotes.
Error 3 — The list data should use square brackets [], not parentheses.
Error 4 — The Dataframe should be DataFrame (capital 'F').
The corrected code is:
import pandas as pd
D1 = {'Name': 'Rakshit', 'Age': 25}
D2 = {'Name': 'Paul', 'Age': 30}
D3 = {'Name': 'Ayesha', 'Age': 28}
data = [D1, D2, D3]
df = pd.DataFrame(data)
print(df)
Answered By
2 Likes
Related Questions
Define the term Primary Key in a database. Explain how it is different from a Candidate Key.
Mention two health concerns associated with excessive use of Digital Devices.
Complete the given Python code to get the required output (ignore the dtype attribute) as
Output:
Tamil Nadu Chennai Uttar Pradesh Lucknow Manipur Imphal
Code:
import _______ as pd data = ['Chennai','_______','Imphal'] indx = ['Tamil Nadu','Uttar Pradesh','Manipur'] s = pd.Series(_______, indx) print(_______)
Ayesha's family is replacing their old computer with a new one. They decide to throw the old computer in a nearby empty field/plot.
I. Explain any one potential environmental hazard associated with improper e-waste disposal.
II. Suggest one responsible way to Ayesha's family for proper disposal of their old computer.
III. Describe the importance of recycling in e-waste management.