小编Joe*_*ndz的帖子

如何在 Seaborn catplot 中指定自定义误差线?

我正在尝试使用 Python 中的 Seaborn 包来可视化一些数据。特别是,我想使用该catplot(kind='bar')函数(以前命名为factorplot())。我的数据框看起来像这样(列'x''col''row'并且'hue'是绝对的):

   x  y        dy col row hue
0  4  9  0.766591   1   0   2
1  5  9  0.688683   0   1   0
2  0  7  0.707982   0   0   1
3  3  6  0.767210   2   1   0
4  3  8  0.287153   0   1   0
Run Code Online (Sandbox Code Playgroud)

我想使用不确定性列'dy'来表示'y'. Seaborn catplots 执行的默认引导或标准偏差误差条不能为我提供令人满意的解决方案。

在这里,我提供了最小完全可验证的示例:

import pandas as pd
import numpy.random as npr
import seaborn as sns

npr.seed(seed=0) …
Run Code Online (Sandbox Code Playgroud)

python seaborn errorbar

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

删除 Pandas 数据框中包含非英语单词的行

我有一个由 4 行组成的 pandas 数据框,英文行包含新闻标题,有些行包含非英文单词,如下所示

\n
**She\xc3\x83\xc2\xa2\xc3\xa2\xe2\x80\x9a\xc2\xac\xc3\xa2\xe2\x80\x9e\xc2\xa2s the Hollywood Power Behind Those ...**\n
Run Code Online (Sandbox Code Playgroud)\n

我想删除像这样的所有行,即 Pandas 数据框中至少包含非英语字符的所有行。

\n

python dataframe python-3.x pandas

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

Pandas 数据透视表列空值不显示

我需要你的帮助:

我有数据框 d3:

数据框

我正在使用数据透视表

df4 = df3.pivot_table(index = ['Number','Department','Task'], columns="Date", values="Score",fill_value = 'N/A')
Run Code Online (Sandbox Code Playgroud)

输出 d4 如下所示:

在此输入图像描述

为什么不显示任务为空的行。我做错了什么?

我想创建这样的数据框:

在此输入图像描述

python pivot-table pandas

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

如何从字典创建 pandas 数据框并将列表保留在一个单元格中

我有一本字典,比如:

dic = {'c': [14, 41],
       'i': '52983542076720',
       'p': 31.7,
       's': 100,
       't': 1611945588012261376,
       'x': 11}
Run Code Online (Sandbox Code Playgroud)

我试过

pd.DataFrame(dic) 
Run Code Online (Sandbox Code Playgroud)

pd.DataFrame.from_dict(dic,, orient='columns', dtype=int, columns=None)
Run Code Online (Sandbox Code Playgroud)

然而,它们都返回一个 2 行数据帧,例如:

C p s t X
0 14 52983542076720 31 100 1611945588012261376 11
1 41 52983542076720 31 100 1611945588012261376 11

我实际上想得到一个像这样的数据框:

C p s t X
0 [14,41] 52983542076720 31 100 1611945588012261376 11

知道我应该做什么才能得到结果吗?

python dictionary dataframe pandas

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

前缀表达式的结果

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

嗨,大家好,

我试图在hackerrank的python中解决上述问题,但我收到错误为:从空列表中弹出 input:expression:+15 和 variables:{} 。请在下面检查我的代码:

def is_operand(c):
return c.isdigit()

def max_result_expression(expression:str,variables: Dict[str, Tuple[int, int]]) ->  Optional[int]:):
stack = []

for c in expression[::-1]:
    if is_operand(c):
        stack.append(int(c))
    else:
        o1 = stack.pop()
        o2 = stack.pop()
        
        if c == '+':
            stack.append(o1+o2)
        elif c == '-':
            stack.append(o1-o2) 
        elif c == '*':
            stack.append(o1*o2)  
        elif c == '/':
            stack.append(o1/o2) 
return stack.pop()

        
Run Code Online (Sandbox Code Playgroud)

prefix python-3.x

-4
推荐指数
1
解决办法
941
查看次数