0
0
Data Analysis Pythondata~10 mins

Creating DataFrames (dict, list, CSV) in Data Analysis Python - 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 a dictionary.

Data Analysis Python
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'
ADataFrame
Bdict
Cpd
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'pd' instead of the data variable.
Trying to pass 'dict' or 'DataFrame' as argument instead of the data.
2fill in blank
medium

Complete the code to create a DataFrame from a list of lists with column names.

Data Analysis Python
import pandas as pd

rows = [[1, 'Apple'], [2, 'Banana'], [3, 'Cherry']]
df = pd.DataFrame([1], columns=['ID', 'Fruit'])
print(df)
Drag options to blanks, or click blank then click option'
Arows
B['ID', 'Fruit']
Cpd.DataFrame
Dcolumns
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the column names as the first argument instead of the data.
Using pd.DataFrame instead of the data variable.
3fill in blank
hard

Fix the error in the code to read a CSV file into a DataFrame.

Data Analysis Python
import pandas as pd

df = pd.read_csv([1])
print(df.head())
Drag options to blanks, or click blank then click option'
Acsv
Bdata.csv
C'data.csv'
Dpd.read_csv
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the file name.
Passing the function name instead of the file path.
4fill in blank
hard

Fill both blanks to create a DataFrame from a dictionary with a condition filtering ages over 20.

Data Analysis Python
import pandas as pd

data = {'Name': ['Anna', 'Ben', 'Cara'], 'Age': [19, 22, 25]}
df = pd.DataFrame([1])
filtered = df[df['Age'] [2] 20]
print(filtered)
Drag options to blanks, or click blank then click option'
Adata
Bdataframe
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong variable name instead of 'data'.
Using '<' instead of '>' for filtering.
5fill in blank
hard

Fill all three blanks to create a DataFrame from a list of dictionaries and select rows where score is above 80.

Data Analysis Python
import pandas as pd

records = [{'name': 'Tom', 'score': 75}, {'name': 'Lucy', 'score': 85}, {'name': 'Jake', 'score': 90}]
df = pd.DataFrame([1])
high_scores = df[df[[2]] [3] 80]
print(high_scores)
Drag options to blanks, or click blank then click option'
Arecords
B'score'
C>
D'name'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable name instead of 'records'.
Using the wrong column name or missing quotes.
Using '<' instead of '>' for filtering.