0
0
Pandasdata~10 mins

Creating DataFrame from dictionary 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 dictionary.

Pandas
import pandas as pd

data = {'name': ['Alice', 'Bob'], 'age': [25, 30]}
df = pd.[1](data)
print(df)
Drag options to blanks, or click blank then click option'
ASeries
Blist
CDataFrame
Darray
Attempts:
3 left
💡 Hint
Common Mistakes
Using pd.Series instead of pd.DataFrame
Trying to use list or array which are not pandas constructors
2fill in blank
medium

Complete the code to create a DataFrame with specified columns order.

Pandas
import pandas as pd

data = {'name': ['Alice', 'Bob'], 'age': [25, 30]}
df = pd.DataFrame(data, columns=[1])
print(df)
Drag options to blanks, or click blank then click option'
A['age']
B['name', 'age']
C['age', 'name']
D['name']
Attempts:
3 left
💡 Hint
Common Mistakes
Passing columns as a string instead of list
Using wrong column names or order
3fill in blank
hard

Fix the error in the code to create a DataFrame from a dictionary of lists.

Pandas
import pandas as pd

data = {'name': ['Alice', 'Bob'], 'age': [25, 30]}
df = pd.DataFrame([1])
print(df)
Drag options to blanks, or click blank then click option'
Adata.keys()
Bdata.items()
Clist(data)
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Passing data.items() which returns a view, not a dict
Passing keys or list of keys instead of the dictionary
4fill in blank
hard

Fill both blanks to create a DataFrame from a dictionary and select only the 'age' column.

Pandas
import pandas as pd

data = {'name': ['Alice', 'Bob'], 'age': [25, 30]}
df = pd.[1](data)
age_column = df[[2]]
print(age_column)
Drag options to blanks, or click blank then click option'
ADataFrame
BSeries
C'age'
D'name'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pd.Series instead of pd.DataFrame
Selecting column with wrong name or without quotes
5fill in blank
hard

Fill all three blanks to create a DataFrame from a dictionary, rename columns, and print the new DataFrame.

Pandas
import pandas as pd

data = {'name': ['Alice', 'Bob'], 'age': [25, 30]}
df = pd.[1](data)
df.columns = [[2], [3]]
print(df)
Drag options to blanks, or click blank then click option'
ADataFrame
B'First Name'
C'Age'
D'name'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to rename columns before creating DataFrame
Assigning column names without quotes or wrong number of names