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

  • 18Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Pandas Basics

What is the purpose of the pip install pandas command?

18 questions

  1. 1

    What is the purpose of the pip install pandas command?

    1. A

      To install the pandas library into the Python environment

    2. B

      To uninstall pandas from the system

    3. C

      To upgrade pandas to the latest version

    4. D

      To create a virtual environment for pandas

    Correct answer
    A

    To install the pandas library into the Python environment

    Explanation

    The command pip install pandas is used to download and install the pandas library into the current Python environment.

  2. 2

    What is the standard alias used when importing pandas?

    1. A

      import pandas as panda

    2. B

      import pandas as pan

    3. C

      import pandas as ps

    4. D

      import pandas as pd

    Correct answer
    D

    import pandas as pd

    Explanation

    The common practice is to import pandas as pd, which is shorter and conventional.

  3. 3

    What are the two core data structures in pandas?

    1. A

      Array and Matrix

    2. B

      Tuple and Set

    3. C

      List and Dictionary

    4. D

      Series and DataFrame

    Correct answer
    D

    Series and DataFrame

    Explanation

    Pandas has two main data structures: Series (1D labeled array) and DataFrame (2D labeled data structure).

  4. 4

    Which method is used to read a CSV file into a pandas DataFrame?

    1. A

      pd.import_csv()

    2. B

      pd.csv_to_df()

    3. C

      pd.read_csv()

    4. D

      pd.load_csv()

    Correct answer
    C

    pd.read_csv()

    Explanation

    The function pd.read_csv() is used to read a CSV file and return a DataFrame.

  5. 5

    What does the head() method return by default?

    1. A

      The first five rows of the DataFrame

    2. B

      All rows with missing values

    3. C

      The last five rows of the DataFrame

    4. D

      The column names and data types

    Correct answer
    A

    The first five rows of the DataFrame

    Explanation

    df.head() returns the first five rows of the DataFrame by default, useful for a quick preview.

  6. 6

    Which method provides descriptive statistics of a DataFrame?

    1. A

      df.describe()

    2. B

      df.summary()

    3. C

      df.stats()

    4. D

      df.analyze()

    Correct answer
    A

    df.describe()

    Explanation

    df.describe() generates descriptive statistics including count, mean, std, min, quartiles, and max.

  7. 7

    How can you access a single column as a Series from a DataFrame df?

    1. A

      df.iloc['column_name']

    2. B

      df.loc['column_name']

    3. C

      df['column_name']

    4. D

      df[['column_name']]

    Correct answer
    C

    df['column_name']

    Explanation

    Using df['column_name'] returns a Series containing the column's values. Double brackets return a DataFrame.

  8. 8

    What does df.iloc[0] return?

    1. A

      The first row as a Series

    2. B

      The entire DataFrame

    3. C

      The first column as a Series

    4. D

      The first row as a DataFrame

    Correct answer
    A

    The first row as a Series

    Explanation

    iloc uses integer-based indexing; df.iloc[0] returns the first row as a Series.

  9. 9

    To update a specific cell based on a condition, which method is commonly used?

    1. A

      df.set_value(condition, 'column', value)

    2. B

      df.iloc[condition, 'column'] = value

    3. C

      df.update()

    4. D

      df.loc[condition, 'column'] = value

    Correct answer
    D

    df.loc[condition, 'column'] = value

    Explanation

    df.loc[condition, 'column'] = value allows updating values where the condition is true.

  10. 10

    Which operator is used to combine multiple conditions in a pandas filter, where all conditions must be true?

    1. A

      & (ampersand)

    2. B

      or

    3. C

      and

    4. D

      | (pipe)

    Correct answer
    A

    & (ampersand)

    Explanation

    In pandas, the & operator is used for element-wise AND when combining boolean arrays.

  11. 11

    How can you filter rows where a string column starts with a specific letter?

    1. A

      df[df['col'].str.starts('letter')]

    2. B

      df[df['col'].startswith('letter')]

    3. C

      df[df['col'].str.like('letter%')]

    4. D

      df[df['col'].str.startswith('letter')]

    Correct answer
    D

    df[df['col'].str.startswith('letter')]

    Explanation

    The .str.startswith() method is used on a string Series to check if each element starts with a given string.

  12. 12

    What does the ~ operator do when used before a condition in pandas?

    1. A

      It checks for missing values

    2. B

      It inverts the boolean condition

    3. C

      It returns the number of rows that match the condition

    4. D

      It casts the condition to a different data type

    Correct answer
    B

    It inverts the boolean condition

    Explanation

    The tilde ~ is used to invert boolean conditions, selecting rows that do NOT satisfy the condition.

  13. 13

    Which method removes rows with any null values?

    1. A

      df.clean()

    2. B

      df.remove_null()

    3. C

      df.dropna()

    4. D

      df.fillna()

    Correct answer
    C

    df.dropna()

    Explanation

    df.dropna() drops rows (or columns) that contain missing values.

  14. 14

    What does inplace=True do in pandas methods?

    1. A

      It returns a new DataFrame with the changes applied

    2. B

      It modifies the original DataFrame directly

    3. C

      It creates a copy of the DataFrame

    4. D

      It raises an error if the operation fails

    Correct answer
    B

    It modifies the original DataFrame directly

    Explanation

    When inplace=True, the operation is performed directly on the original object without returning a new one.

  15. 15

    Which method counts the frequency of each unique value in a Series?

    1. A

      df.value_counts()

    2. B

      df.frequency()

    3. C

      df.count_unique()

    4. D

      df.unique().count()

    Correct answer
    A

    df.value_counts()

    Explanation

    .value_counts() returns a Series containing counts of unique values.

  16. 16

    To group data by a column and compute the sum of another column, which sequence is used?

    1. A

      df.groupby('col1')['col2'].sum()

    2. B

      df.groupby('col1').sum('col2')

    3. C

      df.groupby('col1', 'col2').sum()

    4. D

      df.groupby('col1')['col2'].aggregate(sum)

    Correct answer
    A

    df.groupby('col1')['col2'].sum()

    Explanation

    Common syntax: df.groupby('col1')['col2'].sum() groups by 'col1' and sums 'col2' for each group.

  17. 17

    How can you sort a DataFrame by a column in descending order?

    1. A

      df.order_by('col', descending=True)

    2. B

      df.sort_values(by='col', descending=True)

    3. C

      df.sort_values(by='col', ascending=False)

    4. D

      df.sort('col', reverse=True)

    Correct answer
    C

    df.sort_values(by='col', ascending=False)

    Explanation

    df.sort_values(by='column', ascending=False) sorts the DataFrame in descending order.

  18. 18

    Which method saves a DataFrame to a CSV file without including the index column?

    1. A

      df.write_csv('file.csv', index=False)

    2. B

      df.export_csv('file.csv', no_index=True)

    3. C

      df.save('file.csv', index=False)

    4. D

      df.to_csv('file.csv', index=False)

    Correct answer
    D

    df.to_csv('file.csv', index=False)

    Explanation

    df.to_csv('file.csv', index=False) writes the DataFrame to a CSV file without the row index.

Question 1 of 18
Question 1 of 18

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent