Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从多个列创建打印_Python_Pandas_Dataframe_Matplotlib_Seaborn - Fatal编程技术网

Python 从多个列创建打印

Python 从多个列创建打印,python,pandas,dataframe,matplotlib,seaborn,Python,Pandas,Dataframe,Matplotlib,Seaborn,我正在尝试从多个列创建绘图。数据帧如下所示。正和负应为多个条形,其中模型需要为x 数据帧: Model Positive Negative 0 RNNs 99 1 1 Naive Bayes 22 38 2 Random Forest 51 9 3 SVM Classifier 40 20 我们将非常感谢您的帮助。非常感谢您提供的数据:

我正在尝试从多个列创建绘图。数据帧如下所示。正和负应为多个条形,其中模型需要为x

数据帧:

            Model Positive Negative
0            RNNs       99        1
1     Naive Bayes       22       38
2   Random Forest       51        9
3  SVM Classifier       40       20
我们将非常感谢您的帮助。非常感谢您提供的数据:

import pandas as pd
df = pd.DataFrame(data={'Model':['RNNs','Naive Bayes','Random Forest', 'SVM Classifier'], 
                        'Positive':[99,22,51,40], 
                        'Negative':[1,38,9,20]})

绘图:


使用seaborn和df.melt的另一种方法

import pandas as pd
import seaborn as sns

df = pd.DataFrame(data={'Model':['RNNs','Naive Bayes','Random Forest', 'SVM Classifier'], 
                        'Positive':[99,22,51,40], 
                        'Negative':[1,38,9,20]})
df = df.melt('Model', var_name='cols',  value_name='vals')
g = sns.factorplot(x="Model", y="vals", hue='cols', data=df,kind='bar')
g.set_xticklabels(rotation=90)

你在寻找哪种类型的情节?@JonathanBesomi感谢你的评论。在一个图中,这4个模型有2个条形图。在一个图中,需要分别显示4个模型结果的正和负条形图。谢谢你是什么意思?
import pandas as pd
import seaborn as sns

df = pd.DataFrame(data={'Model':['RNNs','Naive Bayes','Random Forest', 'SVM Classifier'], 
                        'Positive':[99,22,51,40], 
                        'Negative':[1,38,9,20]})
df = df.melt('Model', var_name='cols',  value_name='vals')
g = sns.factorplot(x="Model", y="vals", hue='cols', data=df,kind='bar')
g.set_xticklabels(rotation=90)