【发布时间】:2020-02-05 06:34:42
【问题描述】:
我正在尝试编写一个函数来计算数组中每个项目的小写和大写字母的数量。然后在我的原始表中创建一个新列,将该实例分类为具有更多大写或小写字母。
这是我的数组:
[array([['MARZIA HAS LIGMA LWIAY #0044'],
['This Slinky Montage Is Bizarrely Satisfying to Watch'],
['MAKING HER DREAM COME TRUE! (MAKE A WISH)'],
...,
['THE EVOLUTION OF FORTNITE! 2011 - 2019'],
["India's trucks are works of art"],
['Several airlines change flight routes after Iranian missile downs American drone']],
dtype=object)]
我拥有的功能
Upper=0
Lower=0
for c in range(len(dummy_array)):
for i in c:
if i.isupper():
Upper +=1
elif i.islower():
Lower +=1
else:
pass
if d[Upper] > d[Lower]:
train_data["Caps_in_title"] = 1
else:
train_data["Caps_in_title"] = 0
print(Upper)
print(Lower)
【问题讨论】:
-
问题是什么?有什么问题吗?
-
c是数组索引,而不是数组元素,所以for i in c:没有意义。您应该使用for c in dummy_array:,而不使用range(len(...)) -
您有一个嵌套在列表中的多维数组。您需要嵌套循环来获取各个字符。
-
变量
d指的是什么?
标签: python arrays pandas loops count