You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将Pandas数据框中全大写行提取至新dataframe

筛选Pandas数据框中Name列为全大写的行

原始数据构造

先还原你提供的原始数据框:

import pandas as pd

data = {
    'Name': ['AAA', 'Aaa', 'Abb', 'BBB', 'Baa', 'Bbb'],
    'Index1': [67, 55, 32, 84, 80, 13],
    'Index2': [70, 80, 20, 45, 70, 40]
}
df = pd.DataFrame(data)

核心筛选代码

利用Pandas内置的字符串方法str.isupper()判断Name列值是否全大写,再通过布尔索引提取目标行:

filtered_df = df[df['Name'].str.isupper()]

输出结果

执行代码后得到的filtered_df即为预期结果:

NameIndex1Index2
AAA6770
BBB8445

方法说明

str.isupper()会自动校验字符串中所有字母是否为大写,同时忽略非字母字符(若存在),且要求字符串至少包含一个可大写的字符,完全匹配筛选全大写Name行的需求。

内容的提问来源于stack exchange,提问作者Irfan Khiari

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 21:27:34