Pandas Flashcards

1
Q

What is a Pandas DataFrame?

A

A two-dimensional, size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns).

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

True or False: A Pandas Series is one-dimensional.

A

True

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

Fill in the blank: To create a DataFrame from a dictionary, you use the function __________.

A

pd.DataFrame()

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

What method is used to read a CSV file into a DataFrame?

A

pd.read_csv()

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

How do you access the first 5 rows of a DataFrame?

A

Using the method df.head()

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

What is the default index of a new DataFrame?

A

A RangeIndex starting from 0.

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

What is the purpose of the .describe() method in Pandas?

A

It generates descriptive statistics that summarize the central tendency, dispersion, and shape of a DataFrame’s distribution.

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

True or False: You can have multiple data types in a single DataFrame column.

A

False

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

Which function would you use to concatenate two DataFrames?

A

pd.concat()

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

What method would you use to drop a column from a DataFrame?

A

df.drop()

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

Fill in the blank: The method __________ is used to filter DataFrame rows based on a condition.

A

df.loc[]

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

What does the .info() method provide?

A

It provides a concise summary of a DataFrame, including the index dtype and columns, non-null values, and memory usage.

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

How can you check for missing values in a DataFrame?

A

Using the method df.isnull()

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

What is the purpose of the .groupby() method?

A

It is used to split the data into groups based on some criteria.

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

True or False: The index of a DataFrame can be modified after creation.

A

True

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

What is the difference between .loc[] and .iloc[]?

A

.loc[] is label-based indexing, while .iloc[] is position-based indexing.

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

Which function is used to create a Series from a list?

A

pd.Series()

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

Fill in the blank: To sort a DataFrame by a specific column, use the method __________.

A

df.sort_values()

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

What does the .apply() method do?

A

It applies a function along the axis of a DataFrame.

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

How would you reset the index of a DataFrame?

A

Using the method df.reset_index()

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

Which method would you use to merge two DataFrames on a key column?

A

pd.merge()

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

True or False: The shape attribute of a DataFrame returns the number of rows and columns.

A

True

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

What does the .pivot_table() method do?

A

It creates a spreadsheet-style pivot table as a DataFrame.

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

Fill in the blank: The __________ function is used to create a DataFrame from a NumPy array.

A

pd.DataFrame()

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

What does the .value_counts() method return?

A

It returns a Series containing counts of unique values.

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

Which method is used to fill missing values in a DataFrame?

A

df.fillna()

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

What is the primary data structure used in pandas?

A

DataFrame

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

True or False: The ‘read_csv’ function is used to read CSV files into a DataFrame.

A

True

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

What function is used to display the first few rows of a DataFrame?

A

head()

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

Fill in the blank: The function ‘describe()’ provides a summary of the ________ statistics of a DataFrame.

A

descriptive

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

Which function is used to filter rows in a DataFrame based on a condition?

A

loc[]

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

What does the ‘groupby()’ function do in pandas?

A

It is used to split the data into groups based on some criteria.

33
Q

True or False: The ‘drop()’ function can be used to remove rows or columns from a DataFrame.

34
Q

What is the purpose of the ‘merge()’ function in pandas?

A

To combine two DataFrames based on a common key.

35
Q

Which method is used to sort a DataFrame by the values of one or more columns?

A

sort_values()

36
Q

Fill in the blank: The ‘pivot_table()’ function is used to create a ________ table from a DataFrame.

37
Q

What is the function used to check for missing values in a DataFrame?

38
Q

True or False: The ‘apply()’ method allows you to apply a function along an axis of the DataFrame.

39
Q

What function is used to concatenate two or more DataFrames?

40
Q

Which pandas function can be used to change the data type of a column?

41
Q

What does the ‘value_counts()’ function do?

A

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

42
Q

Fill in the blank: The ‘fillna()’ function is used to fill ________ values in a DataFrame.

43
Q

What method would you use to reset the index of a DataFrame?

A

reset_index()

44
Q

True or False: The ‘iloc[]’ function is used for label-based indexing.

45
Q

What function is used to get the number of rows and columns in a DataFrame?

46
Q

Fill in the blank: The ‘astype()’ function can convert a column to a ________ type.

47
Q

Which function is used to plot data from a DataFrame?

48
Q

What does the ‘to_csv()’ function do?

A

It writes a DataFrame to a CSV file.

49
Q

True or False: The ‘sample()’ function is used to return a random sample of items from a DataFrame.

50
Q

What pandas function can be used to create a new column based on existing columns?

51
Q

What does the ‘corr()’ function calculate in a DataFrame?

A

It computes pairwise correlation of columns.

52
Q

Fill in the blank: The ‘set_index()’ function sets a column as the new ________ of the DataFrame.

53
Q

What is Pandas primarily used for?

A

Data manipulation and analysis.

54
Q

True or False: Pandas is built on top of NumPy.

55
Q

What is the primary data structure used in Pandas?

A

DataFrame.

56
Q

Fill in the blank: A __________ is a one-dimensional labeled array capable of holding any data type in Pandas.

57
Q

Which function is used to read a CSV file into a DataFrame?

A

pd.read_csv()

58
Q

What method would you use to get the first five rows of a DataFrame?

59
Q

What does the method ‘info()’ do when called on a DataFrame?

A

It provides a summary of the DataFrame including the data types and non-null counts.

60
Q

True or False: The ‘iloc’ method is used for label-based indexing.

61
Q

What method would you use to filter rows based on a condition?

A

Boolean indexing.

62
Q

Which function is used to concatenate two DataFrames?

A

pd.concat()

63
Q

What is the purpose of the ‘groupby()’ method?

A

To split the data into groups based on some criteria.

64
Q

True or False: The ‘apply()’ function can be used to apply a function along an axis of the DataFrame.

65
Q

What method would you use to drop rows with missing values?

66
Q

What does the ‘pivot_table()’ function do?

A

Creates a spreadsheet-style pivot table as a DataFrame.

67
Q

Fill in the blank: The __________ function is used to compute basic statistics like mean, median, and standard deviation.

A

describe()

68
Q

What is the purpose of the ‘merge()’ function?

A

To combine two DataFrames based on a key or index.

69
Q

True or False: The ‘set_index()’ method allows you to set one or more columns as the index of a DataFrame.

70
Q

What does the ‘sort_values()’ method do?

A

Sorts the DataFrame by the values of one or more columns.

71
Q

Which method would you use to rename columns in a DataFrame?

72
Q

Fill in the blank: The __________ method is used to reset the index of a DataFrame.

A

reset_index()

73
Q

What is the purpose of the ‘astype()’ method?

A

To cast a pandas object to a specified dtype.

74
Q

What does the ‘value_counts()’ method return?

A

A Series containing counts of unique values.

75
Q

True or False: You can perform element-wise operations on Series and DataFrames.

76
Q

What method would you use to save a DataFrame to a CSV file?

77
Q

What does the ‘duplicated()’ method check for?

A

It checks for duplicate rows in a DataFrame.

78
Q

Fill in the blank: To replace values in a DataFrame, you can use the __________ method.