QuizLander
← 所有公开测验

Python — Pandas: DataFrames & data analysis

作者 Jude · 23/05/2026 · 149 次浏览 · 0 次分享

Series, DataFrame, loc/iloc, groupby, merge, missing data, time series. 20 questions.
20
题目
🇬🇧 English
语言
中等
难度
开始测验(游客或账户)
分享为图片

测验题目

  1. 1. Which Pandas structure represents a single labeled column?
    1. DataFrame
    2. Series
    3. Index
    4. ndarray
  2. 2. Difference between df.loc[...] and df.iloc[...]?
    1. None
    2. loc indexes by label, iloc by integer position
    3. iloc is deprecated
    4. loc works only on rows
  3. 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. [1, 2, 3]
    2. 6
    3. (1, 2, 3)
    4. Error
  4. 4. Which selects rows where age >= 18?
    1. df.where(age >= 18)
    2. df[df['age'] >= 18]
    3. df.filter('age >= 18')
    4. df.select('age >= 18')
  5. 5. What does this return?
    df = pd.DataFrame({'g': ['a', 'b', 'a'], 'v': [10, 20, 30]})
    print(df.groupby('g')['v'].sum().to_dict())
    1. {'a': 40, 'b': 20}
    2. {'a': 10, 'b': 20}
    3. {'a': 30, 'b': 20}
    4. Error
  6. 6. How do you join two DataFrames on a common column (SQL-style)?
    1. append
    2. concat
    3. merge
    4. join by default
  7. 7. Default behavior of df.dropna()?
    1. Fills NaN with 0
    2. Drops rows with at least one NaN
    3. Drops columns with any NaN
    4. Returns a bool
  8. 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())
    1. [4, 6]
    2. [3, 6]
    3. [1, 2, 3, 4]
    4. Error
  9. 9. How do you set an existing column as the index?
    1. df.set_index('col')
    2. df.reindex('col')
    3. df.index = 'col'
    4. df['col'].as_index()
  10. 10. Difference between apply, map and applymap?
    1. None
    2. Series.map elementwise; DataFrame.apply per column/row; DataFrame.applymap elementwise (deprecated in 2.1+, use DataFrame.map)
    3. apply only works on the index
    4. map is slower than applymap
  11. 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. 1
    2. 99
    3. NaN
    4. Error
  12. 12. Which produces multi-aggregation per group?
    1. df.groupby('g').agg({'v': ['mean', 'std']})
    2. df.groupby('g').sum_mean()
    3. df.groupby('g').multiagg(['mean', 'std'])
    4. df.groupby('g').describe(['mean', 'std'])
  13. 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())
    1. [30, 30]
    2. [60]
    3. [10, 50]
    4. [30, 50]
  14. 14. How do you read a CSV with the date column parsed and set as index?
    1. pd.read_csv(p, index_col='date', parse_dates=['date'])
    2. pd.read_csv(p, dates=True)
    3. pd.read_csv(p).set_dates()
    4. pd.read_csv(p, header='date')
  15. 15. How do you fill NaN with the mean?
    1. s.fillna(s.mean())
    2. s.replace(NaN, mean)
    3. s.dropna().mean()
    4. s.mean().fillna()
  16. 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'))
    1. Wide table with index d, columns a/b; missing combos = NaN
    2. Error
    3. A 1D Series
    4. A long-format table
  17. 17. What does df.dtypes return?
    1. The global Python type of df
    2. A Series mapping each column to its dtype
    3. A set of all dtypes
    4. The index dtype
  18. 18. Why is df['col'].str.lower() faster than a Python loop?
    1. It isn't
    2. The .str accessor applies the op in C across the column without a Python loop
    3. It caches the result
    4. It JITs on the fly
  19. 19. Recommended dtype for a column with a small set of repeated values (e.g., statuses)?
    1. object
    2. str
    3. category
    4. bytes
  20. 20. What does this print?
    df = pd.DataFrame({'a': [1, 2, 3, 4]})
    print(df.rolling(window=2).sum()['a'].tolist())
    1. [NaN, 3.0, 5.0, 7.0]
    2. [1.0, 3.0, 5.0, 7.0]
    3. [3.0, 5.0, 7.0]
    4. Error
答题并查看我的分数

评论

登录后即可评论。

加载中…