python-3.x - 在 python 上使用 swarmplot 绘制和建模文本数据
问题描述
我有一个 csv 文件,我想使用 seaborn 库的 swarmplot 来绘制两个选定列之间的关系。
这是我正在使用的 csv 文件中的 5 行示例
SeriesCode Year DESCRIPTION
21 IC.FRM.CORR.ZS YR2004 The sample was drawn from the manufacturing sector only.
38 SP.ADO.TFRT YR2010 Interpolated using data for 2007 and 2012.
10 SP.ADO.TFRT YR2000 Interpolated using data for 1997 and 2002.
18 IC.FRM.CORR.ZS YR2003 The sample was drawn from the manufacturing sector only.
32 IC.TAX.METG YR2007 The sample was drawn from the manufacturing sector only.
28 SP.ADO.TFRT YR2006 Interpolated using data for 2002 and 2007.
我有这段代码
import re
import pandas
df1=pandas.read_csv("./Jobs_csv/JobsSeries-Time.csv")
ifcz=df1[df1['SeriesCode'].str.contains("IC.FRM.CORR.ZS",flags=re.IGNORECASE,regex=True)].DESCRIPTION
ify=df1[df1['SeriesCode'].str.contains("IC.FRM.CORR.ZS",flags=re.IGNORECASE,regex=True)].Year
sb.swarmplot(x="ifcz", y="ify", data=df1)
但每当我运行它
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-68-3c5933ceba52> in <module>()
----> 1 sb.swarmplot(x="ifcz", y="ify", data=df1)
/home/user/.local/lib/python3.6/site-packages/seaborn/categorical.py in swarmplot(x, y, hue, data, order, hue_order, dodge, orient, color, palette, size, edgecolor, linewidth, ax, **kwargs)
2975
2976 plotter = _SwarmPlotter(x, y, hue, data, order, hue_order,
-> 2977 dodge, orient, color, palette)
2978 if ax is None:
2979 ax = plt.gca()
/home/user/.local/lib/python3.6/site-packages/seaborn/categorical.py in __init__(self, x, y, hue, data, order, hue_order, dodge, orient, color, palette)
1214 dodge, orient, color, palette):
1215 """Initialize the plotter."""
-> 1216 self.establish_variables(x, y, hue, data, orient, order, hue_order)
1217 self.establish_colors(color, palette, 1)
1218
/home/user/.local/lib/python3.6/site-packages/seaborn/categorical.py in establish_variables(self, x, y, hue, data, orient, order, hue_order, units)
150 if isinstance(var, str):
151 err = "Could not interpret input '{}'".format(var)
--> 152 raise ValueError(err)
153
154 # Figure out the plotting orientation
ValueError: Could not interpret input 'ifcz'
我收到这些错误。我不知道它为什么会出现此错误或如何修复它。而且我不确定是否应该使用 swarmplot。如果你认为这是因为不应该使用 swarmplot,那么你能说出其他的吗情节来建模这个?
解决方案
推荐阅读
- python - 在 Microsoft Azure 上部署 Flask WebApp
- css - 如何在容器(CSS)中对齐?
- javascript - 如何将引导日期时间选择器作为动态数组
- r - 我是新来的。如何将数据框变量值从数字转换为名称?请参阅下面的代码
- java - 使用spring数据优化mongodb的计数
- c# - 排序列表,其中前任和后继定义排序
- ios - 为什么 React Native iOS 模拟器的重新加载快捷方式有时会停止工作?
- javascript - Gridsome/Netlify CMS 文档导致 Graphql 损坏
- c++ - 通过 DirectX12 工具包绘制球体
- python - 如何使用具有 Google Cloud 权限的 PyCharm 调试器?