首页 \ 问答 \ 如何加入pandas数据帧,以便seaborn boxplot或violinplot可以使用列作为色调?(How to join pandas dataframe so that seaborn boxplot or violinplot can use a column as hue?)

如何加入pandas数据帧,以便seaborn boxplot或violinplot可以使用列作为色调?(How to join pandas dataframe so that seaborn boxplot or violinplot can use a column as hue?)

我有一个包含多列的数据框,我可以轻松地使用seaborn在boxplot(或小提琴图等)中绘制它,如下所示:

data1 = {'p0':[1.,2.,5,0.], 'p1':[2., 1.,1,3], 'p2':[3., 3.,2., 4.]}
df1 = pd.DataFrame.from_dict(data1)
sns.boxplot(data=df1)

在此处输入图像描述

我现在需要的是将这个数据框与另一个数据框合并,这样我就可以在一个箱形图中绘制它们,就像在这里完成的那样: http//seaborn.pydata.org/examples/grouped_boxplot.html

我试过添加一个列并连接。 结果似乎没问题

data1 = {'p0':[1.,2.,5,0.], 'p1':[2., 1.,1,3], 'p2':[3., 3.,2., 4.]}
data2 = {'p0':[3.,1.,5,1.], 'p1':[3., 2.,3,3], 'p2':[1., 2.,2., 5.]}
df1 = pd.DataFrame.from_dict(data1)
df1['method'] = 'A'
df2 = pd.DataFrame.from_dict(data2)
df2['method'] = 'B'
df_all = pd.concat([df1,df2])
sns.boxplot(data=df_all)

这有效,但它将方法A和B中的数据汇总在一起。但是这会失败:

sns.boxplot(data=df_all, hue='method')

因为我需要指定x和y。 如果我将x指定为x=['p0', 'p1', 'p2'] ,则将3列进行平均。 所以我想我可以用不同的方式合并数据帧,这样它的表示就像seaborn一样简单。


I have a dataframe with multiple columns, and I can easily use seaborn to plot it in a boxplot (or violinplot, etc), like this:

data1 = {'p0':[1.,2.,5,0.], 'p1':[2., 1.,1,3], 'p2':[3., 3.,2., 4.]}
df1 = pd.DataFrame.from_dict(data1)
sns.boxplot(data=df1)

enter image description here

What I now need is to merge this dataframe with another one, so that I can plot them in a single boxplot, just as is done here: http://seaborn.pydata.org/examples/grouped_boxplot.html

I have tried adding a column and concatenating. The result seems ok

data1 = {'p0':[1.,2.,5,0.], 'p1':[2., 1.,1,3], 'p2':[3., 3.,2., 4.]}
data2 = {'p0':[3.,1.,5,1.], 'p1':[3., 2.,3,3], 'p2':[1., 2.,2., 5.]}
df1 = pd.DataFrame.from_dict(data1)
df1['method'] = 'A'
df2 = pd.DataFrame.from_dict(data2)
df2['method'] = 'B'
df_all = pd.concat([df1,df2])
sns.boxplot(data=df_all)

This works, but it plots together data from methods A and B. However this fails:

sns.boxplot(data=df_all, hue='method')

because I then need to specify x and y. If I specify x as x=['p0', 'p1', 'p2'], them the 3 columns are averaged. So I guess I can merge the dataframes in a different way so that its representation is simple with seaborn.


原文:https://stackoverflow.com/questions/44162416
更新时间:2023-06-27 06:06

最满意答案

为了提高可见性,我将在这里发布hbarck的链接:

CodePlex上的resx Manager工具

它是一个非常轻量级且简单易用的应用程序,它使用项目的resx文件创建XML,并将它们放在一个漂亮的Excel文件中,每个语言都在一列中,每个子项目的文件都有一个表格。

警告:在Excel中打开文件时,请对“仍然打开”对话框说“是”。 保存时说NO“转换?” 对话框(保留Excel XML 2003格式,否则您很难将翻译恢复到项目中)。

有关说明,请参阅CodePlex上的文档。 如果您有任何问题,请不要向我哭泣,我只是发布链接:-P

希望这也有助于其他人!


Just to improve visibility I'll post hbarck's link here:

resx Manager Tool at CodePlex

It is a very lightweight and straightforward app that creates an XML with your project's resx files, and puts them in a nice Excel file with each language in a column, and a sheet for each sub-project's files.

Warning: when opening the file in Excel, say YES to "open anyway" dialog. When saving say NO to "convert?" dialog (keep Excel XML 2003 format or you will have a hard time getting your translations back to your project).

For instructions see the documentation at CodePlex. If you have any problem, don't come crying to me, I'm just posting the link :-P

Hope this helps someone else too!

相关问答

更多
  • 查看WPF全球化和本地化概述 。 这篇文章很好地解释了WPF中的本地化是如何工作的。 Check out WPF Globalization and Localization Overview. The article explains nicely how localization in WPF works.
  • 以下MSDN文章ASP.NET 2.0中的资源和本地化 - 显示本地化图像状态: 虽然ASP.NET 2.0不直接支持本地化图像文件,但它不需要太多的自定义代码即可达到所需的效果。 并提供以下解决方法: 您可以通过将本地化版本的图像文件添加到本地化版本的全局资源文件开始。 例如,英文版LitwareSlogan.png已添加到名为Litware.resx的全局资源文件中,而LitwareSlogan.fr.png的法文版已添加到Litware.fr.resx中。 两个资源文件中的资源都被命名为Litware ...
  • 如果主程序集(MyApp.resx)中的资源属于en-US文化,则无需创建MyApp.en-US.resx文件。 如果没有找到此文化的附属程序集,资源管理器将回退到主程序集中的资源。 If the resources in the main assembly (MyApp.resx) are in the en-US culture, you don't need to create a MyApp.en-US.resx file. If no satellite assembly is found for ...
  • 由于您使用的是WPF,因此您可以将相关的字符串和图像定义为资源,并为每个客户使用单独的ResourceDictionary (Xaml资源文件)。 在您的应用程序资源中,您可以先导入默认资源,然后导入您的客户特定覆盖。 这将会是最后一步,因此客户文件中存在的任何资源将优先于默认文件中的资源。 同样,如果资源未在客户资源中定义,您将使用默认值中的资源。
  • 为了使用resoiurces你必须:1。在xaml中包含资源文件 xmlns:resource ="clr-namespace:WpfApplication1.Strings.en_US" 你可以使用绑定像: 如果你做这些事情尝试重建项目。 Xaml无法确定您是否包含新文件并生成错误。 在我的资源文件中,我有:名称=问候值=样本测试 希望这可以帮助。 in order to use r ...
  • 修改我的帖子有点更具包容性: 这里有关于MSDN的详细总体最佳实践。 真的,你有三个选择。 自己进行本地化 - 手动滚动自己的XML /文本文件/数据库解决方案。 使用locbaml进行本地化。 这不允许在app中动态语言切换。 使用resx文件进行本地化。 这允许在应用程序中动态语言切换,具体取决于所选的实现。 在很多情况下,locbaml是最佳的,在最佳实践页面上列出,但resx文件相当便携(格式很简单),并且将满足动态语言交换的要求。 如果您决定选择(1),那么您就是自己的。 一帆风顺! :) 如果您 ...
  • 我看到两种选择,其中没有一种是理想的... 列举所有已知文化(CultureInfo.GetCultures),并尝试获得这种文化的给定资源=>简单但缓慢 在应用程序目录中查找卫星程序集:对于每个子目录,检查它的名称是否与文化名称(CultureInfo.GetCultureInfo)相对应,以及它是否包含.resources.dll文件 I see two options, none of which is ideal... Enumerate all known cultures (CultureInf ...
  • 为了提高可见性,我将在这里发布hbarck的链接: CodePlex上的resx Manager工具 它是一个非常轻量级且简单易用的应用程序,它使用项目的resx文件创建XML,并将它们放在一个漂亮的Excel文件中,每个语言都在一列中,每个子项目的文件都有一个表格。 警告:在Excel中打开文件时,请对“仍然打开”对话框说“是”。 保存时说NO“转换?” 对话框(保留Excel XML 2003格式,否则您很难将翻译恢复到项目中)。 有关说明,请参阅CodePlex上的文档。 如果您有任何问题,请不要向我 ...
  • 您需要从StaticResource切换到DynamicResource ,因为您的资源不是立即可用的。 但是您不能在ResourceDictionary属性上使用Bindings,因为它不是从DependencyObject派生的。 You would need to switch from StaticResource to DynamicResource, since your resource isn't immediately available. But you cannot using Bin ...
  • Grant Frisken实际帮助我解决了这个问题: “为窗口指定的DefaultResxName不适用于Window.Resource,因为该资源不是窗口的框架元素。因此您必须显式设置ResxName属性。例如:” Grant Frisken actually helped me to solve this prob ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)