【发布时间】:2017-04-02 18:40:06
【问题描述】:
我有一个数据框
graph 0 1 2 3 4
1 blue blue blue blue blue
2 blue blue blue blue blue
3 blue red blue blue red
4 red blue red red blue
5 red red blue red red
6 blue blue blue blue blue
我需要获取每个字符串/行的值“蓝色”的计数。
所需的输出:
graph result
1 5
2 5
3 3
4 2
5 1
6 5
我尝试这样做
(df['0', '1', '2', '3', '4']).applymap(lambda x: str.count(x, 'blue'))
但它会返回
KeyError: ('0', '1', '2', '3', '4')
【问题讨论】: