【发布时间】:2015-07-24 20:45:05
【问题描述】:
我正在尝试使用下面的 pandas 数据框根据模式查找项目属于哪个类别
数据
ITEM CATEGORY
1 red saree actual
2 red saree actual
3 glass lbh
4 glass lbh
5 red saree actual
6 red saree lbh
7 glass actual
8 bottle actual
9 bottle actual
我想弄清楚的是,我想根据类别的模式为每个独特的项目分配一个类别。
预期输出:
ITEM CATEGORY
1 red saree actual
2 glass lbh
3 bottle actual
请告诉我如何在 python 中查找,提前谢谢
试过了:
import pandas as pd
from scipy.stats import mode
data_x = map(mode, data['category'])
我知道它甚至与那个无关,但无法找到如何编写代码
【问题讨论】:
-
7 glass actual去哪儿了? -
我要问的是! ,我们有一个物品(玻璃),有 3 个类别(实际,磅,磅),那么物品(玻璃)的类别模式是磅。我如何使用 python 分配
-
为什么是
lbh而不是actual?