← 所有公开测验
开始测验(游客或账户)
Python — Pandas: DataFrames & data analysis
作者 Jude · 23/05/2026 · 149 次浏览 · 次分享
Series, DataFrame,
loc/iloc, groupby, merge, missing data, time series. 20 questions.
20
题目
🇬🇧 English
语言
中等
难度
测验题目
-
1. Which Pandas structure represents a single labeled column?
DataFrameSeriesIndexndarray
-
2. Difference between
df.loc[...]anddf.iloc[...]?- None
locindexes by label,ilocby integer positionilocis deprecatedlocworks only on rows
-
3. What does this print?
import pandas as pd df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]}) print(df['a'].sum())- [1, 2, 3]
- 6
- (1, 2, 3)
- Error
-
4. Which selects rows where
age >= 18?df.where(age >= 18)df[df['age'] >= 18]df.filter('age >= 18')df.select('age >= 18')
-
5. What does this return?
df = pd.DataFrame({'g': ['a', 'b', 'a'], 'v': [10, 20, 30]}) print(df.groupby('g')['v'].sum().to_dict())- {'a': 40, 'b': 20}
- {'a': 10, 'b': 20}
- {'a': 30, 'b': 20}
- Error
-
6. How do you join two DataFrames on a common column (SQL-style)?
appendconcatmergejoinby default
-
7. Default behavior of
df.dropna()?- Fills NaN with 0
- Drops rows with at least one NaN
- Drops columns with any NaN
- Returns a bool
-
8. What is
df['c']after this?df = pd.DataFrame({'a': [1, 2], 'b': [3, 4]}) df['c'] = df['a'] + df['b'] print(df['c'].tolist())- [4, 6]
- [3, 6]
- [1, 2, 3, 4]
- Error
-
9. How do you set an existing column as the index?
df.set_index('col')df.reindex('col')df.index = 'col'df['col'].as_index()
-
10. Difference between
apply,mapandapplymap?- None
Series.mapelementwise;DataFrame.applyper column/row;DataFrame.applymapelementwise (deprecated in 2.1+, useDataFrame.map)applyonly works on the indexmapis slower thanapplymap
-
11. What does this print?
df = pd.DataFrame({'x': [1, 2, 3]}) s = df['x'] s.iloc[0] = 99 print(df['x'].iloc[0])- 1
- 99
- NaN
- Error
-
12. Which produces multi-aggregation per group?
df.groupby('g').agg({'v': ['mean', 'std']})df.groupby('g').sum_mean()df.groupby('g').multiagg(['mean', 'std'])df.groupby('g').describe(['mean', 'std'])
-
13. What does this return?
idx = pd.date_range('2024-01-01', periods=3, freq='D') s = pd.Series([10, 20, 30], index=idx) print(s.resample('2D').sum().tolist())- [30, 30]
- [60]
- [10, 50]
- [30, 50]
-
14. How do you read a CSV with the
datecolumn parsed and set as index?pd.read_csv(p, index_col='date', parse_dates=['date'])pd.read_csv(p, dates=True)pd.read_csv(p).set_dates()pd.read_csv(p, header='date')
-
15. How do you fill NaN with the mean?
s.fillna(s.mean())s.replace(NaN, mean)s.dropna().mean()s.mean().fillna()
-
16. What does this pivot produce?
df = pd.DataFrame({'d': ['x','x','y'], 'k': ['a','b','a'], 'v': [1,2,3]}) print(df.pivot(index='d', columns='k', values='v'))- Wide table with index d, columns a/b; missing combos = NaN
- Error
- A 1D Series
- A long-format table
-
17. What does
df.dtypesreturn?- The global Python type of df
- A Series mapping each column to its dtype
- A set of all dtypes
- The index dtype
-
18. Why is
df['col'].str.lower()faster than a Python loop?- It isn't
- The
.straccessor applies the op in C across the column without a Python loop - It caches the result
- It JITs on the fly
-
19. Recommended dtype for a column with a small set of repeated values (e.g., statuses)?
objectstrcategorybytes
-
20. What does this print?
df = pd.DataFrame({'a': [1, 2, 3, 4]}) print(df.rolling(window=2).sum()['a'].tolist())- [NaN, 3.0, 5.0, 7.0]
- [1.0, 3.0, 5.0, 7.0]
- [3.0, 5.0, 7.0]
- Error