Seaborn:如何用条形图中的X轴替换索引?(Seaborn: How to replace index with text in X-Axis in barplot?)
我有一个带有
category
列的数据集,它有表示类标签的整数值,即0,1,2 ......我有单独的文件,其中包含该类别的文本标签,即对于索引0,它包含
classA
,依此类推。 我想用下面的代码用seaborn绘制一个条形图。import seaborn as sns train_df = pd.read_csv("unclean_text.csv", sep='\t') label_text = pd.read_csv("labels.csv") is_dup = train_df['category'].value_counts() plt.figure(figsize=(8,4)) sns.barplot(is_dup.index, is_dup.values, alpha=0.8, color=color[1]) plt.show()
它正确地绘制了每个班级频率的条形图。
但是我想要x轴上的文本标签而不是
label_text
的索引值,label_text
也是长度为19(0-18)的列向量。 怎么做?I have a dataset with
category
column which has integer values representing class label i.e 0,1,2.....I have separate file which contains text labels for that category i.e against index 0, it contains
classA
and so on. I want to plot a barplot using seaborn with following code.import seaborn as sns train_df = pd.read_csv("unclean_text.csv", sep='\t') label_text = pd.read_csv("labels.csv") is_dup = train_df['category'].value_counts() plt.figure(figsize=(8,4)) sns.barplot(is_dup.index, is_dup.values, alpha=0.8, color=color[1]) plt.show()
It correctly plots the barplot for frequency of each class.
But I want text labels on the x-axis instead of index values that are in
label_text
, which is also a column vector of length 19 (0-18). How to do it?
原文:https://stackoverflow.com/questions/45729609
最满意答案
我认为您需要找到max(优先级)并在连接中包含它以限制返回的行。 例如
SELECT * FROM routine_actions AS ra JOIN routines AS r ON r.id = ra.routine_id JOIN account_routines AS ar ON ar.routine_id = r.id JOIN ( SELECT account_id , MAX(priority) AS max_priority FROM account_routines GROUP BY account_id ) AS mxr ON ar.priority = mxr.max_priority AND ar.account_id = mxr.account_id JOIN accounts AS a ON a.id = ar.account_id WHERE ...
I think you need to locate the max(priority) and include that in the joins to limit the rows returned. e.g.
SELECT * FROM routine_actions AS ra JOIN routines AS r ON r.id = ra.routine_id JOIN account_routines AS ar ON ar.routine_id = r.id JOIN ( SELECT account_id , MAX(priority) AS max_priority FROM account_routines GROUP BY account_id ) AS mxr ON ar.priority = mxr.max_priority AND ar.account_id = mxr.account_id JOIN accounts AS a ON a.id = ar.account_id WHERE ...
相关问答
更多-
WITH recordList AS ( SELECT a.Product_TypeID, a.ProductID, a.Product_Category, b.Priority, ROW_NUMBER() OVER (PARTITION BY a.ProductID ORDER BY b.Priority) RN FROM ...
-
我做了一个实验来证明这一点,如下: process1:RT priority = 40,CPU affinity = CPU 0.这个进程“旋转”10秒,所以它不会让任何较低优先级的进程在CPU 0上运行。 process2:RT priority = 39,CPU affinity = CPU 0.此过程每0.5秒向stdout打印一条消息,睡在两者之间。 它打印出每个消息的消逝时间。 我正在运行带有PREEMPT_RT补丁的2.6.33内核。 要运行实验,我在一个窗口中以root身份运行process2 ...
-
您可以使用FIRST_VALUE分析函数: SELECT FIRST_VALUE( C ) OVER ( ORDER BY CASE C WHEN 'max' THEN 3 WHEN 'avg' THEN 2 WHEN 'min' THEN 1 ELSE 0 END DESC ) FROM T; ...
-
如果最高优先级指令没有,则元素不会收到隔离范围(Element does not get isolate scope if highest priority directive does not have one)[2023-07-16]
简短的回答是 。 有两个指令需要一个隔离范围和一个父范围是没有意义的。 这个想法是想想如何指令可以相互工作。 如果父范围指令的范围是隔离范围,它将如何正确工作? 我猜测这个角色团队决定在这种情况下不给出警告(可能是一个bug)。 如果较低的优先级需要隔离范围,这意味着它对来自父范围的数据有严格的要求 如果较高优先级不需要范围,这意味着它将继承父范围并可能在模板中使用该数据。 这是一种捕捉22的情况:非隔离指令使用隔离范围是没有意义的,因为它可能取决于它不是隔离的事实。 同时,隔离指令很可能取决于它是隔离的事 ... -
我认为您需要找到max(优先级)并在连接中包含它以限制返回的行。 例如 SELECT * FROM routine_actions AS ra JOIN routines AS r ON r.id = ra.routine_id JOIN account_routines AS ar ON ar.routine_id = r.id JOIN ( SELECT account_id ...
-
SQL Server - 使用按位运算符查找最高优先级项(SQL Server - Finding the Highest Priority item using Bitwise operators)[2023-02-03]
SELECT * FROM PrimaryData pd CROSS APPLY ( SELECT TOP 1 * FROM Exception e WHERE e.Mask & pd.Exceptions <> 0 ORDER BY e.Priority ) q SELECT * FROM PrimaryData pd CROSS APPLY ... -
你可以用row_number()来做到这一点: select field1, field2, field3, field4 from (select t.*, row_number() over (partition by field1 order by (case when field2 = 'W' then 1 when ...
-
UPDATE表为tb1,表为tb2 SET tb2.priority = tb2.priority - 1 WHERE tb2.priority> tb1.priority AND tb1.text ='action'AND tb2.subcategory = tb1.subcategory; 这应该解决差距,每个具有更高id的项目应该将其降低1 即你在这个子类别: | priority | | 1 | | 2 | | 3 | | 4 | 如果您移动 ...
-
根据联接优先级列的最低值选择不同的标识行(Selecting distinct identity rows based on the lowest value of a joined priority column)[2022-11-27]
这个问题是“每组最大n”问题的变体,但是你要找的是最小的而不是最大的问题,你的标准是在查找表( Type )而不是主表( Attributes )中。 因此,您需要来自Attributes的行( a1 ),以使具有相同node_id其他行与较低优先级相关联。 SELECT a1.* FROM Attributes a1 INNER JOIN Type t1 ON (a1.type_id = t1.id) LEFT OUTER JOIN ( (Attributes a2 INNER JOIN Type t ... -
select guid, min(priority) from (SELECT *, case when category = 'E' then 1 when category = 'W' then 2 when category = 'S' then 3 end as priority FROM TABLENAME WHERE CATEGORY in ('S','E','W') ) a 内部查询根据问题为category列分配优先级。 在外部查询中,您可以从具有最高优 ...