0
0
Pandasdata~10 mins

Creating DataFrame from list of lists 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 lists named data.

Pandas
import pandas as pd
data = [[1, 'Alice'], [2, 'Bob'], [3, 'Charlie']]
df = pd.[1](data)
Drag options to blanks, or click blank then click option'
Aread_csv
BSeries
CPanel
DDataFrame
Attempts:
3 left
💡 Hint
Common Mistakes
Using Series instead of DataFrame causes wrong data structure.
Using read_csv tries to read from a file, not from a list.
2fill in blank
medium

Complete the code to assign column names 'ID' and 'Name' to the DataFrame.

Pandas
import pandas as pd
data = [[1, 'Alice'], [2, 'Bob'], [3, 'Charlie']]
df = pd.DataFrame(data, columns=[1])
Drag options to blanks, or click blank then click option'
A['ID', 'Name']
B'ID, Name'
C('ID', 'Name')
D{'ID', 'Name'}
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of a list causes a single column named with the whole string.
Using a set changes the order and causes errors.
3fill in blank
hard

Fix the error in the code to create a DataFrame from data with columns 'A' and 'B'.

Pandas
import pandas as pd
data = [[10, 20], [30, 40]]
df = pd.DataFrame(data, columns=[1])
Drag options to blanks, or click blank then click option'
A['A', 'B']
B'A, B'
C['A']
D['A', 'B', 'C']
Attempts:
3 left
💡 Hint
Common Mistakes
Giving more or fewer column names than data columns causes errors.
Passing a string instead of a list causes wrong column names.
4fill in blank
hard

Fill both blanks to create a DataFrame from data and set the index to the first column.

Pandas
import pandas as pd
data = [[101, 'John'], [102, 'Jane'], [103, 'Doe']]
df = pd.DataFrame(data, columns=[1]).set_index([2])
Drag options to blanks, or click blank then click option'
A['ID', 'Name']
B'ID'
C'Name'
D['Name', 'ID']
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong column name for index causes unexpected results.
Passing columns as a string instead of a list causes errors.
5fill in blank
hard

Fill all three blanks to create a DataFrame from data, name columns, and select rows where 'Age' is greater than 25.

Pandas
import pandas as pd
data = [[1, 'Anna', 22], [2, 'Ben', 30], [3, 'Cara', 27]]
df = pd.DataFrame(data, columns=[1])
adults = df[df[[2]] [3] 25]
Drag options to blanks, or click blank then click option'
A['ID', 'Name', 'Age']
B'Age'
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' selects wrong rows.
Not using a list for columns causes errors.
Using wrong column name in filter causes empty results.