Pandas Flashcards

(78 cards)

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
What does the .value_counts() method return?
It returns a Series containing counts of unique values.
26
Which method is used to fill missing values in a DataFrame?
df.fillna()
27
What is the primary data structure used in pandas?
DataFrame
28
True or False: The 'read_csv' function is used to read CSV files into a DataFrame.
True
29
What function is used to display the first few rows of a DataFrame?
head()
30
Fill in the blank: The function 'describe()' provides a summary of the ________ statistics of a DataFrame.
descriptive
31
Which function is used to filter rows in a DataFrame based on a condition?
loc[]
32
What does the 'groupby()' function do in pandas?
It is used to split the data into groups based on some criteria.
33
True or False: The 'drop()' function can be used to remove rows or columns from a DataFrame.
True
34
What is the purpose of the 'merge()' function in pandas?
To combine two DataFrames based on a common key.
35
Which method is used to sort a DataFrame by the values of one or more columns?
sort_values()
36
Fill in the blank: The 'pivot_table()' function is used to create a ________ table from a DataFrame.
pivot
37
What is the function used to check for missing values in a DataFrame?
isnull()
38
True or False: The 'apply()' method allows you to apply a function along an axis of the DataFrame.
True
39
What function is used to concatenate two or more DataFrames?
concat()
40
Which pandas function can be used to change the data type of a column?
astype()
41
What does the 'value_counts()' function do?
It returns a Series containing counts of unique values in a column.
42
Fill in the blank: The 'fillna()' function is used to fill ________ values in a DataFrame.
NaN
43
What method would you use to reset the index of a DataFrame?
reset_index()
44
True or False: The 'iloc[]' function is used for label-based indexing.
False
45
What function is used to get the number of rows and columns in a DataFrame?
shape
46
Fill in the blank: The 'astype()' function can convert a column to a ________ type.
specific
47
Which function is used to plot data from a DataFrame?
plot()
48
What does the 'to_csv()' function do?
It writes a DataFrame to a CSV file.
49
True or False: The 'sample()' function is used to return a random sample of items from a DataFrame.
True
50
What pandas function can be used to create a new column based on existing columns?
assign()
51
What does the 'corr()' function calculate in a DataFrame?
It computes pairwise correlation of columns.
52
Fill in the blank: The 'set_index()' function sets a column as the new ________ of the DataFrame.
index
53
What is Pandas primarily used for?
Data manipulation and analysis.
54
True or False: Pandas is built on top of NumPy.
True.
55
What is the primary data structure used in Pandas?
DataFrame.
56
Fill in the blank: A __________ is a one-dimensional labeled array capable of holding any data type in Pandas.
Series.
57
Which function is used to read a CSV file into a DataFrame?
pd.read_csv()
58
What method would you use to get the first five rows of a DataFrame?
head()
59
What does the method 'info()' do when called on a DataFrame?
It provides a summary of the DataFrame including the data types and non-null counts.
60
True or False: The 'iloc' method is used for label-based indexing.
False.
61
What method would you use to filter rows based on a condition?
Boolean indexing.
62
Which function is used to concatenate two DataFrames?
pd.concat()
63
What is the purpose of the 'groupby()' method?
To split the data into groups based on some criteria.
64
True or False: The 'apply()' function can be used to apply a function along an axis of the DataFrame.
True.
65
What method would you use to drop rows with missing values?
dropna()
66
What does the 'pivot_table()' function do?
Creates a spreadsheet-style pivot table as a DataFrame.
67
Fill in the blank: The __________ function is used to compute basic statistics like mean, median, and standard deviation.
describe()
68
What is the purpose of the 'merge()' function?
To combine two DataFrames based on a key or index.
69
True or False: The 'set_index()' method allows you to set one or more columns as the index of a DataFrame.
True.
70
What does the 'sort_values()' method do?
Sorts the DataFrame by the values of one or more columns.
71
Which method would you use to rename columns in a DataFrame?
rename()
72
Fill in the blank: The __________ method is used to reset the index of a DataFrame.
reset_index()
73
What is the purpose of the 'astype()' method?
To cast a pandas object to a specified dtype.
74
What does the 'value_counts()' method return?
A Series containing counts of unique values.
75
True or False: You can perform element-wise operations on Series and DataFrames.
True.
76
What method would you use to save a DataFrame to a CSV file?
to_csv()
77
What does the 'duplicated()' method check for?
It checks for duplicate rows in a DataFrame.
78
Fill in the blank: To replace values in a DataFrame, you can use the __________ method.
replace()