Dataframes and manipulating data Flashcards
What does df.head() do?
Returns the first 5 rows of the DataFrame.
How to show the last 5 rows of a DataFrame?
Use df.tail().
How to get column names?
Use df.columns.
How to get row indices?
Use df.index.
What does df.info() display?
Summarizes DataFrame structure (data types, non-null counts).
What is the purpose of df.describe()?
Generates statistical summary (mean, std, min, max, etc.).
How to count unique values per column?
Use df.nunique().
How to filter rows where height is over 200 cm?
Use df[df[‘height_cm’] > 200].
How to select specific rows and columns using labels?
Use df.loc[rows, columns].
How to sort by ‘Units Sold’ in descending order?
Use df.sort_values(‘Units Sold’, ascending=False).
How to iterate over DataFrame rows?
Use df.iterrows().
How to load a CSV file?
Use pd.read_csv(‘file_path’).
How to filter rows where ‘name’ contains ‘Mike’?
Use df[df[‘name’].str.contains(‘Mike’)].
How to query rows where born_country is ‘IND’ or ‘USA’?
Use df.query(‘born_country == "IND" or born_country == "USA"’).
What does df.shape return?
A tuple representing (rows, columns).