Dataframes and manipulating data Flashcards

1
Q

What does df.head() do?

A

Returns the first 5 rows of the DataFrame.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to show the last 5 rows of a DataFrame?

A

Use df.tail().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to get column names?

A

Use df.columns.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to get row indices?

A

Use df.index.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does df.info() display?

A

Summarizes DataFrame structure (data types, non-null counts).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the purpose of df.describe()?

A

Generates statistical summary (mean, std, min, max, etc.).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to count unique values per column?

A

Use df.nunique().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to filter rows where height is over 200 cm?

A

Use df[df[‘height_cm’] > 200].

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to select specific rows and columns using labels?

A

Use df.loc[rows, columns].

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to sort by ‘Units Sold’ in descending order?

A

Use df.sort_values(‘Units Sold’, ascending=False).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to iterate over DataFrame rows?

A

Use df.iterrows().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to load a CSV file?

A

Use pd.read_csv(‘file_path’).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to filter rows where ‘name’ contains ‘Mike’?

A

Use df[df[‘name’].str.contains(‘Mike’)].

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to query rows where born_country is ‘IND’ or ‘USA’?

A

Use df.query(‘born_country == "IND" or born_country == "USA"’).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does df.shape return?

A

A tuple representing (rows, columns).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly