Docsity

Pandas 32 problems with functions, Assignments of Advanced Data Analysis

Toggle sidebar
bg1
Week 5: Pandas Fundamentals I โ€“ 32 Problem Statements
1. Read a CSV file into a DataFrame and print its first 5 rows.
2. Use info() to check data types and non-null values.
3. Display basic statistics of numerical columns using describe().
4. Select a specific column and calculate its mean.
5. Select multiple columns from a DataFrame.
6. Use .iloc to access the first three rows and two columns.
7. Use .loc to access rows with specific labels.
8. Add a new column to a DataFrame based on existing columns.
9. Rename columns in a DataFrame.
10. Replace missing values with column mean.
11. Drop rows with missing values and compare the shapes.
12. Sort the DataFrame by a specific column.
13. Filter rows based on a numerical condition.
14. Filter rows based on multiple conditions.
15. Reset the index of a DataFrame.
16. Set a specific column as the new index.
17. Count the frequency of unique values in a categorical column.
18. Group data by a column and find the average of each group.
19. Create a new column using apply() with a custom function.
20. Write a filtered DataFrame to a new CSV file.
21. Use value_counts() to find how often each category appears.
22. Access the last 10 rows of a DataFrame using .tail().
23. Rename specific row indices.
24. Create a copy of a DataFrame and modify it.
25. Replace a value in the entire DataFrame.
26. Check for duplicate rows and remove them.
27. Concatenate two DataFrames vertically.
pf3

Partial preview of the text

Download Pandas 32 problems with functions and more Assignments Advanced Data Analysis in PDF only on Docsity!

Week 5: Pandas Fundamentals I โ€“ 32 Problem Statements

  1. Read a CSV file into a DataFrame and print its first 5 rows.
  2. Use info() to check data types and non-null values.
  3. Display basic statistics of numerical columns using describe().
  4. Select a specific column and calculate its mean.
  5. Select multiple columns from a DataFrame.
  6. Use .iloc to access the first three rows and two columns.
  7. Use .loc to access rows with specific labels.
  8. Add a new column to a DataFrame based on existing columns.
  9. Rename columns in a DataFrame.
  10. Replace missing values with column mean.
  11. Drop rows with missing values and compare the shapes.
  12. Sort the DataFrame by a specific column.
  13. Filter rows based on a numerical condition.
  14. Filter rows based on multiple conditions.
  15. Reset the index of a DataFrame.
  16. Set a specific column as the new index.
  17. Count the frequency of unique values in a categorical column.
  18. Group data by a column and find the average of each group.
  19. Create a new column using apply() with a custom function.
  20. Write a filtered DataFrame to a new CSV file.
  21. Use value_counts() to find how often each category appears.
  22. Access the last 10 rows of a DataFrame using .tail().
  23. Rename specific row indices.
  24. Create a copy of a DataFrame and modify it.
  25. Replace a value in the entire DataFrame.
  26. Check for duplicate rows and remove them.
  27. Concatenate two DataFrames vertically.
  1. Add a column with default value using assign().
  2. Create a DataFrame from a Python dictionary.
  3. Round all numerical values to two decimal places.
  4. Create a DataFrame with custom index and column names.
  5. Convert a column's datatype (e.g., object to int).

Functions / Methods Used

  1. pd.read_csv() โ€” reads a CSV file into a DataFrame.
  2. .head() โ€” displays the first n rows of the DataFrame (default is 5).
  3. .info() โ€” displays column data types, non-null counts, and memory usage.
  4. .describe() โ€” generates basic statistics for numerical columns.
  5. df['col'].mean() โ€” calculates the mean of a specific column.
  6. df[['col1', 'col2']] โ€” selects multiple columns from a DataFrame.
  7. .iloc[] โ€” accesses rows and columns by integer position.
  8. .loc[] โ€” accesses rows and columns by label.
  9. df['new_col'] = ... โ€” creates a new column based on existing columns.
  10. .rename(columns={}) โ€” renames DataFrame columns.
  11. .fillna() โ€” replaces missing values (e.g., with column mean).
  12. .dropna() โ€” removes rows or columns with missing values.
  13. .sort_values() โ€” sorts a DataFrame by one or more columns.
  14. df[df['col'] > value] โ€” filters rows by a numerical condition.
  15. df[(cond1) & (cond2)] โ€” filters rows by multiple conditions.
  16. .reset_index() โ€” resets the index of the DataFrame.
  17. .set_index() โ€” sets a specified column as the index.
  18. .value_counts() โ€” counts frequency of unique values in a Series.
  19. .groupby().mean() โ€” groups data and calculates the average of each group.
  20. .apply() โ€” applies a custom function to rows or columns.
  21. .to_csv() โ€” writes a DataFrame to a CSV file.
  22. .value_counts() โ€” counts occurrences of each category in a column.
  23. .tail() โ€” returns the last n rows of the DataFrame.
  24. .rename(index={}) โ€” renames specific row indices.
  25. .copy() โ€” creates a copy of the DataFrame.
  26. .replace() โ€” replaces values throughout the DataFrame.
  27. .duplicated() โ€” checks for duplicate rows.
  28. .drop_duplicates() โ€” removes duplicate rows.
  29. pd.concat() โ€” concatenates multiple DataFrames.
  30. .assign() โ€” adds a new column with a default or computed value.
  31. pd.DataFrame() โ€” creates a DataFrame from a dictionary or other data.
  32. .round() โ€” rounds numerical values to a specified number of decimals.