每个字母都用大写

2024-04-20 12:24:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个dataframe,我想创建一个新列,其值等于另一列中大写字母的和/计数。(最快的方式,因为我有一个半木pc) 例如:

         Col1                     Upper

1      AfK is Bad                   3
2      Afk is bad                   1
3      Python better than R         2

编辑: 我试过这个:

 for i in df.index:
     df['Upper'].iloc[[i]] = sum(1 for c in (df['Upper'].iloc[[i]]) if c.isupper())

Col1在哪里

非常感谢!你知道吗


Tags: indataframedfforis方式大写字母upper