小编ada*_*ama的帖子

Python:列表数组中的唯一值

图像此输出来自fuzzywuzzy(值可能在另一个序列中):

[('car', 100, 28),
 ('tree', 80, 5),
 ('house', 44, 12),
 ('house', 44, 25),
 ('house', 44, 27)]
Run Code Online (Sandbox Code Playgroud)

我想把这三者一视同仁houses。只有唯一的字符串值才能得到这个结果的有效方法是什么:

编辑:由于所有houses值都相同44,我不在乎列表中的哪一个。最后一个house值无关紧要)

[('car', 100, 28),
 ('tree', 80, 5),
 ('house', 44, 12)]
Run Code Online (Sandbox Code Playgroud)

我在这里看到了很多关于列表唯一性的问题,但答案对我的示例不起作用,主要是因为作者只需要一个列表的解决方案。

我试过这个:

unique = []
for element in domain1:
    if element[0] not in unique:
        unique.append(element)
Run Code Online (Sandbox Code Playgroud)

我想我可以使用第一个值来处理element[0]并检查它们是否存在于unique. 如果我打印,unique我的结果与 after 相同fuzzywuzzy。似乎我的想法没有走在正确的道路上,那么我怎样才能达到我想要的结果呢?

谢谢!

python tuples list

2
推荐指数
1
解决办法
223
查看次数

使用每日数据集绘制以月份为 x 轴的 seaborn boxplot

我有一个这样的数据集:

>>> print(ds.head())

         date     sum
  0  2013-08-31  19.000
  1  2013-09-01  37.000
  2  2013-09-02  10.750
  3  2013-09-03  21.500
  4  2013-09-04  44.125

>>> print(ds.tail())


            date      sum
    1742  2018-08-24  129.875
    1743  2018-08-25  196.375
    1744  2018-08-26  247.000
    1745  2018-08-27  104.125
    1746  2018-08-28  149.250
Run Code Online (Sandbox Code Playgroud)

该数据集包含大约 1700 行的每日数据。我想绘制一个箱线图,以便查看每月的值。像这样的东西 每月箱线图

我需要像 JAN/FEB/MAR 等 x 轴上的月份。

如果我有每日数据集,我找不到任何可行的解决方案来实现这一目标。我想我必须先做数据准备并首先对每个月的值进行分组?或者我如何以简单快捷的方式进行编程?

python boxplot seaborn

1
推荐指数
1
解决办法
8611
查看次数

标签 统计

python ×2

boxplot ×1

list ×1

seaborn ×1

tuples ×1