AI-Agent 面试题汇总 - Python数据分析篇(二)
1-什么是 DataFrame?
DataFrame 是 pandas 的二维表结构,带有行索引和列索引,每列可以是不同数据类型,适合做结构化数据分析。
2-什么是索引(index)?有什么作用?
索引是行标签,用于数据定位、切片、对齐和快速检索;时间序列分析中常把日期设为索引。
3-如何查看每列的数据类型?
df.dtypes
4-如何查看每列缺失值数量?
df.isna().sum()
5-如何判断数据中是否存在缺失值?
df.isna().values.any()
6-如何提取 createTime 为空的行?
df[df["createTime"].isna()]
7-如何删除所有存在缺失值的行?
df.dropna()
8-如何将 salary 列转换为浮点数?
df["salary"] = df["salary"].astype(float)
9-如何计算 salary 最大值与最小值之差?
df["salary"].max() - df["salary"].min()
10-如何查看每种学历出现次数?
df["education"].value_counts()
11-如何统计 education 列共有几种学历?
df["education"].nunique()
12-如何计算 salary > 10000 的数量?
(df["salary"] > 10000).sum()
13-如何提取 salary 与 new 之和大于 60000 的最后 3 行?
df[(df["salary"] + df["new"]) > 60000].tail(3)
14-如何将 createTime 列设置为索引?
df = df.set_index("createTime")
15-如何重置索引为默认整数索引?
df = df.reset_index(drop=True)
16-如何生成与 df 长度相同的随机数 DataFrame?
import numpy as np import pandas as pd rand_df = pd.DataFrame(np.random.rand(len(df), 1), columns=["rand"])
17-如何将随机数 DataFrame 与 df 横向合并?
df2 = pd.concat([df, rand_df], axis=1)
18-如何新增列 new = salary - rand?
df2["new"] = df2["salary"] - df2["rand"]
19-如何将第一行与最后一行拼接?
pd.concat([df.head(1), df.tail(1)], axis=0)
20-如何将第 8 行添加到末尾?
df = pd.concat([df, df.iloc[[7]]], ignore_index=True)
21-如何绘制收盘价折线图(close)?
import matplotlib.pyplot as plt df["close"].plot() plt.show()
22-如何同时绘制开盘价与收盘价?
df[["open", "close"]].plot() plt.show()
23-如何绘制涨跌幅直方图(pctChg)?
df["pctChg"].hist(bins=20) plt.show()
24-如何让直方图更细致?
增大 bins 数量。
df["pctChg"].hist(bins=50) plt.show()
25-如何绘制换手率密度曲线(turn)?
df["turn"].plot(kind="kde") plt.show()
26-如何计算前一天与后一天收盘价差值?
df["close_diff"] = df["close"].diff()
27-如何计算前一天与后一天收盘价变化率?
df["close_pct"] = df["close"].pct_change()
28-如何按周重采样并取收盘价最大值?
df["date"] = pd.to_datetime(df["date"])
df = df.set_index("date")
weekly_max = df["close"].resample("W").max()
29-如何计算收盘价 5 日均线与 5 日滚动和?
df["ma5"] = df["close"].rolling(5).mean() df["sum5"] = df["close"].rolling(5).sum()
30-如何将收盘价向后移动5天、向前移动5天?
df["close_lag5"] = df["close"].shift(5) # 滞后5天 df["close_lead5"] = df["close"].shift(-5) # 超前5天
AI-Agent面试实战专栏 文章被收录于专栏
本专栏聚焦 AI-Agent 面试高频考点,内容来自真实面试与项目实践。系统覆盖大模型基础、Prompt工程、RAG、Agent架构、工具调用、多Agent协作、记忆机制、评测、安全与部署优化等核心模块。以“原理+场景+实战”为主线,提供高频题解析、标准答题思路与工程落地方法,帮助你高效查漏补缺.