0
0
Pandasdata~10 mins

Creating DataFrame from list of dictionaries in Pandas - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a DataFrame from the list of dictionaries named data.

Pandas
import pandas as pd
data = [{'name': 'Alice', 'age': 25}, {'name': 'Bob', 'age': 30}]
df = pd.[1](data)
print(df)
Drag options to blanks, or click blank then click option'
Aconcat
BDataFrame
CSeries
Dread_csv
Attempts:
3 left
💡 Hint
Common Mistakes
Using pd.Series instead of pd.DataFrame
Trying to read data with pd.read_csv when data is already in memory
2fill in blank
medium

Complete the code to print the first two rows of the DataFrame df.

Pandas
import pandas as pd
data = [{'name': 'Alice', 'age': 25}, {'name': 'Bob', 'age': 30}, {'name': 'Cara', 'age': 22}]
df = pd.DataFrame(data)
print(df.[1](2))
Drag options to blanks, or click blank then click option'
Asample
Btail
Chead
Ddescribe
Attempts:
3 left
💡 Hint
Common Mistakes
Using tail() which shows the last rows
Using describe() which summarizes statistics
3fill in blank
hard

Fix the error in the code to create a DataFrame from data.

Pandas
import pandas as pd
data = [{'name': 'Alice', 'age': 25}, {'name': 'Bob', 'age': 30}]
df = pd.DataFrame[1]data
print(df)
Drag options to blanks, or click blank then click option'
A(data)
B[data]
Cdata
D{data}
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting parentheses after DataFrame
Using square or curly brackets instead of parentheses
4fill in blank
hard

Fill both blanks to create a DataFrame from data and select only the 'name' column.

Pandas
import pandas as pd
data = [{'name': 'Alice', 'age': 25}, {'name': 'Bob', 'age': 30}]
df = pd.[1](data)
names = df[[2]]
print(names)
Drag options to blanks, or click blank then click option'
ADataFrame
B'age'
C'name'
DSeries
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting the wrong column name
Using Series instead of DataFrame to create the table
5fill in blank
hard

Fill all three blanks to create a DataFrame from data, filter rows where age is greater than 25, and print the result.

Pandas
import pandas as pd
data = [{'name': 'Alice', 'age': 25}, {'name': 'Bob', 'age': 30}, {'name': 'Cara', 'age': 22}]
df = pd.[1](data)
filtered = df[df[[2]] [3] 25]
print(filtered)
Drag options to blanks, or click blank then click option'
ADataFrame
B'age'
C>
D'name'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong column name for filtering
Using wrong comparison operator
Forgetting to create the DataFrame first