1. Home
  2. Explore
  3. Computer Science
  4. Pandas Library Fundamentals

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Pandas Library Fundamentals

  • 38Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Fundamentals and Setup

What is pandas and what is it used for?

38 questions

  1. 1

    What is pandas and what is it used for?

    Model answer

    Pandas is an open-source Python library designed for data manipulation and analysis.

    Explanation

    Pandas is widely used in data science, AI, and machine learning for handling structured data.

  2. 2

    What are the two core data structures in pandas?

    Model answer

    Series (a 1D labeled array) and DataFrame (a 2D labeled data structure like a spreadsheet or SQL table).

    Explanation

    A Series represents a single column or row, while a DataFrame represents a full table of data.

  3. 3

    What is the standard import statement for pandas?

    Model answer

    import pandas as pd

    Explanation

    It is common practice to alias pandas as pd for brevity.

  4. 4

    How do you install pandas using pip on Windows?

    Model answer

    Run pip install pandas in the terminal or command prompt.

    Explanation

    This command installs pandas from PyPI.

  5. 5

    How do you install pandas on Mac or Linux?

    Model answer

    Use pip3 install pandas in the terminal.

    Explanation

    On Unix-based systems, pip is often for Python 2, so pip3 is used for Python 3.

  6. 6

    How can you set up a virtual environment for pandas using UV?

    Model answer

    Use uv init . to create a virtual environment, then uv add pandas to install pandas, and run scripts with uv run script.py.

    Explanation

    UV provides a fast way to manage Python virtual environments.

  7. 7

    How do you load a CSV file into a pandas DataFrame?

    Model answer

    Use pd.read_csv('filename.csv') which returns a DataFrame.

    Explanation

    This is the most common way to import tabular data into pandas.

  8. 8

    What other file formats can pandas read besides CSV?

    Model answer

    Pandas can read Excel spreadsheets, and you can also manually create a DataFrame from a dictionary.

    Explanation

    pd.read_excel('file.xlsx') loads Excel data; pd.DataFrame(dict) creates from a dictionary.

  9. 9

    How can you create a DataFrame from a dictionary?

    Model answer

    Pass a dictionary where keys are column names and values are lists of data to pd.DataFrame(dict).

    Explanation

    Each key-value pair becomes a column in the DataFrame.

  10. 10

    What are default row indices in a DataFrame?

    Model answer

    By default, rows are assigned integer indices starting from 0.

    Explanation

    This index is automatically generated when loading or creating a DataFrame.

  11. 11

    What does the head() method do?

    Model answer

    It returns the first 5 rows of the DataFrame.

    Explanation

    Useful for quickly inspecting the beginning of the data.

  12. 12

    What does the tail() method do?

    Model answer

    It returns the last 5 rows of the DataFrame.

    Explanation

    Complementary to head() for checking the end of the data.

  13. 13

    What information does info() provide?

    Model answer

    It provides general information such as the number of entries, columns, and data types of each column.

    Explanation

    Useful for understanding the structure and memory usage of the DataFrame.

  14. 14

    What does describe() do?

    Model answer

    It generates descriptive statistics summarizing central tendency, dispersion, and shape of the data.

    Explanation

    Provides summary statistics for numeric columns by default.

  15. 15

    How do you get a list of column names in a DataFrame?

    Model answer

    Use df.columns.

    Explanation

    Returns an Index object containing the column labels.

  16. 16

    What does df.index return?

    Model answer

    It returns a RangeIndex object with start, stop, and step.

    Explanation

    The index is a built-in pandas object used for row identification.

  17. 17

    How do you access a single column from a DataFrame?

    Model answer

    Use df['column_name'] or df.column_name, which returns a Series.

    Explanation

    Bracket notation and dot notation are equivalent for column access.

  18. 18

    How do you access multiple columns?

    Model answer

    Use df[['col1', 'col2']], which returns a DataFrame.

    Explanation

    Pass a list of column names inside the brackets to select multiple columns.

  19. 19

    How do you access a row by its integer position?

    Model answer

    Use df.iloc[row_index], which returns a Series.

    Explanation

    iloc stands for integer location, used for positional indexing.

  20. 20

    How do you access a row by a label or condition?

    Model answer

    Use df.loc[condition] or df.loc[row_label] for label-based selection.

    Explanation

    loc is used for label-based indexing, often with boolean conditions.

  21. 21

    How do you filter rows where a column equals a specific value?

    Model answer

    Use df[df['col'] == value].

    Explanation

    The condition inside the brackets returns a boolean Series used to filter rows.

  22. 22

    How do you apply multiple filter conditions with AND?

    Model answer

    Use & between conditions, each enclosed in parentheses: df[(condition1) & (condition2)].

    Explanation

    The ampersand & acts as a logical AND operator for element-wise comparison.

  23. 23

    How do you apply multiple filter conditions with OR?

    Model answer

    Use | between conditions: df[(condition1) | (condition2)].

    Explanation

    The pipe | acts as a logical OR operator.

  24. 24

    How do you filter rows using a string method like 'starts with'?

    Model answer

    Use df['col'].str.startswith('pattern').

    Explanation

    The .str accessor enables vectorized string methods on a Series.

  25. 25

    How do you filter rows where a column value is in a list?

    Model answer

    Use df['col'].isin(['val1', 'val2']).

    Explanation

    The isin method checks membership of each element in the given list.

  26. 26

    How do you invert a filter condition?

    Model answer

    Use the tilde operator ~ before the condition.

    Explanation

    The ~ operator negates the boolean condition.

  27. 27

    How do you update a value in a specific row and column?

    Model answer

    Use df.loc[condition, 'column'] = new_value.

    Explanation

    loc selects the rows that meet the condition, then the column is assigned a new value.

  28. 28

    How do you apply a transformation to an entire column (e.g., convert to uppercase)?

    Model answer

    Assign the transformed column: df['col'] = df['col'].str.upper().

    Explanation

    This replaces the original column with the transformed version.

  29. 29

    How do you drop a row by its index?

    Model answer

    Use df.drop(index).

    Explanation

    The drop method removes the specified row index and returns a new DataFrame by default.

  30. 30

    How do you drop rows with any missing values?

    Model answer

    Use df.dropna().

    Explanation

    This removes any row that contains at least one missing (NaN) value.

  31. 31

    How do you fill missing values with a specific value?

    Model answer

    Use df.fillna(value).

    Explanation

    This replaces all NaN values with the specified value.

  32. 32

    What does the inplace=True parameter do?

    Model answer

    It modifies the existing DataFrame instead of returning a new one.

    Explanation

    When inplace=True, the operation is performed directly on the original object.

  33. 33

    How do you rename a column in a DataFrame?

    Model answer

    Use df.rename(columns={'old_name': 'new_name'}, inplace=True).

    Explanation

    The columns parameter maps old column names to new ones.

  34. 34

    What does value_counts() do?

    Model answer

    It returns a Series containing counts of unique values in a column.

    Explanation

    This is useful for frequency analysis of categorical data.

  35. 35

    How do you group data by a column and sum another column?

    Model answer

    Use df.groupby('col')['another_col'].sum().

    Explanation

    groupby creates groups, then an aggregation function like sum is applied to the specified column.

  36. 36

    What does groupby() return before aggregation?

    Model answer

    It returns a GroupBy object, which can then have aggregation methods like sum(), mean(), etc.

    Explanation

    The GroupBy object is a special object that supports split-apply-combine operations.

  37. 37

    How do you sort a DataFrame by a column?

    Model answer

    Use df.sort_values('col', ascending=True/False).

    Explanation

    The ascending parameter controls the sort order (True for ascending, False for descending).

  38. 38

    How do you save a DataFrame to a CSV file?

    Model answer

    Use df.to_csv('filename.csv', index=True/False).

    Explanation

    The index parameter determines whether to include the row index in the output file.

1 of 38
Question 1 of 38

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent