[go: up one dir, main page]

0% found this document useful (0 votes)
29 views6 pages

Pandas Test

The document contains a series of multiple-choice questions related to DataFrame operations in Python's pandas library. Each question tests knowledge on various functionalities such as data selection, manipulation, and analysis. The questions cover topics like indexing, handling missing values, grouping, sorting, and merging DataFrames.

Uploaded by

lokeshbhs11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views6 pages

Pandas Test

The document contains a series of multiple-choice questions related to DataFrame operations in Python's pandas library. Each question tests knowledge on various functionalities such as data selection, manipulation, and analysis. The questions cover topics like indexing, handling missing values, grouping, sorting, and merging DataFrames.

Uploaded by

lokeshbhs11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1. What does df.shape return?

a) The number of missing values in the DataFrame


b) The number of rows and columns in a tuple
c) The first and last row of the DataFrame
d) The column names
2. How can you select only the 'Name' and 'Salary'
columns from df?
d) df[['Name', 'Salary']]
c) df.select(['Name', 'Salary'])
b) df.get(['Name', 'Salary'])
a) df.columns(['Name', 'Salary'])
3. What will df.iloc[2:5] return?
b) Rows at index 2, 3, and 4
c) Rows at index 2, 3, 4, and 5
d) The entire DataFrame except rows 2 to 5
a) Only the 5th row
4. How can you replace all NaN values with 0 in df?
c) df.fillna(0, inplace=True)
a) df.replace_na(0)
b) df.nulls(0)
d) df.remove_na(0)
5. What does df.dtypes return?
d) Data types of each column
b) Only numeric columns
c) Only categorical columns
a) Number of unique values in each column
6. What does df.set_index('Customer_ID', inplace=True) do?
a) Sets 'Customer_ID' as the index column
d) Deletes the 'Customer_ID' column
c) Sorts DataFrame by 'Customer_ID'
b) Changes 'Customer_ID' values
7. How do you get the first 10 rows of df?
c) df.head(10)
a) df.first(10)
d) df.select(10)
b) df.iloc[:10]
8. Which function returns the number of unique values in
a column?
b) df['col'].nunique()
d) df['col'].unique_count()
a) df['col'].distinct()
c) df['col'].value_counts()
9. How do you drop rows with missing values in any
column?
d) df.dropna()
c) df.null_remove()
b) df.remove_na()
a) df.dropnulls()
10. What is the correct way to add a new column df['Tax'] =
df['Salary'] * 0.1?

a) df['Tax'] = df['Salary'] * 0.1


d) df.new_column('Tax', df['Salary'] * 0.1)
c) df.add_col('Tax', df['Salary'] * 0.1)
b) df.append_col('Tax', df['Salary'] * 0.1)
11. How can you group data by 'Department' and get
average salary?
b) df.groupby('Department')['Salary'].mean()
d) df.group('Department').agg({'Salary': 'mean'})
c) df.aggregate('Department', 'mean')
a) df.mean('Department', 'Salary')
12. How do you sort df by column 'Age' in descending
order?
c) df.sort_values('Age', ascending=False)
a) df.sort('Age', order='desc')
d) df.order_by('Age', descending=True)
b) df.desc_sort('Age')
13. What does df[df['Salary'] > 50000] do?
d) Returns only rows where Salary is greater than 50,000
a) Deletes rows where Salary is more than 50,000
c) Replaces salaries above 50,000 with NaN
b) Adds a new column with filtered salaries
14. What does df.info() provide?
a) Summary of DataFrame structure, data types, and non-null
values
d) Only the column names and data types
c) Detailed statistical analysis of numeric columns
b) The last 5 rows of the DataFrame
15. How do you get all column names of df?
c) df.columns
a) df.col_names()
d) df.show_columns()
b) df.list_columns()

16. How do you check if any column in df has duplicate


values?
b) df.duplicated().any()
c) df.has_duplicates()
a) df.duplicates_exist()
d) df.check_dupes()
17. What does df['Salary'].apply(lambda x: x + 5000) do?
d) Adds 5000 to each salary value
b) Rounds salaries to 5000
c) Sets all salaries to 5000
a) Removes salaries below 5000
18. How do you concatenate df1 and df2 vertically?
c) pd.concat([df1, df2], axis=0)
a) df1.append(df2)
b) df1.join(df2, how='outer')
d) df1.merge(df2)
19. How do you merge df1 and df2 on a common column
'ID'?
a) df1.merge(df2, on='ID')
d) df1.join(df2, on='ID')
c) df1.combine(df2, on='ID')
b) df1.concat(df2, on='ID')
20. What will df.pivot_table(values='Sales', index='Region',
columns='Year') do?

b) Creates a summary table with Sales grouped by Region and


Year
d) Deletes Sales data
a) Creates a new column named Sales
c) Filters Sales for a specific year
21. How do you reset the index of df?
d) df.reset_index(inplace=True)
b) df.drop_index()
c) df.set_index(0)
a) df.index_reset()
22. How do you get the row with the highest salary?
c) df[df['Salary'] == df['Salary'].max()]
d) df.highest_row('Salary')
a) df.top_row('Salary')
b) df.iloc[df['Salary'].idxmax()]
23. What does df['Department'].value_counts() do?
b) Counts occurrences of each unique value in 'Department'
d) Sorts values in 'Department'
c) Returns the sum of numeric columns
a) Replaces duplicate values
24. What is the use of df.corr()?
a) Computes correlation between numeric columns
c) Counts missing values
d) Finds unique column values
b) Deletes NaN values

You might also like