简体   繁体   English

plot a dataframe 这样一列是一组绘制的符号作为其他列的 function | python

[英]plot a dataframe so that one column is a set of plotted signs as a function of the other columns | python

For the lack of a better explanation, I will add a picture.由于缺乏更好的解释,我将添加图片。 This is my dataframe:这是我的 dataframe:

df_for_plot
Out[403]: 
                           hour  dow  month  to
timestamp                                      
2019-06-24 00:00:00+00:00     0    0      6   1
2019-06-24 01:00:00+00:00     1    0      6   1
2019-06-24 02:00:00+00:00     2    0      6   1
2019-06-24 03:00:00+00:00     3    0      6   2
2019-06-24 04:00:00+00:00     4    0      6   2
                        ...  ...    ...  ..
2019-09-20 19:00:00+00:00    19    4      9   1
2019-09-20 20:00:00+00:00    20    4      9   1
2019-09-20 21:00:00+00:00    21    4      9   1
2019-09-20 22:00:00+00:00    22    4      9   1
2019-09-20 23:00:00+00:00    23    4      9   1

[34848 rows x 4 columns]

set(df_for_plot["to"])
Out[404]: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

I would like to plot something like this so that hour and dow are representing the values on the axis and the to column will be plotted as a variable, represented by some signs, like in this visual example I quickly drew我想要 plot 这样的东西,这样hourdow代表轴上的值, to列将被绘制为一个变量,由一些符号表示,就像我快速绘制的这个视觉示例

在此处输入图像描述

Is there a way to do something like this in python?有没有办法在 python 中做这样的事情?

You can use scatterplot from seaborn with pd.cut for grouping your values:您可以使用 seaborn 中的scatterplotpd.cut对您的值进行分组:

import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

rng = np.random.default_rng(2022)
df = pd.DataFrame({'hour': rng.integers(0, 24, 30),
                   'dow': rng.integers(0, 5, 30),
                   'to': rng.integers(0, 11, 30)})

df['cat'] = pd.cut(df['to'], [1, 4, 7, 10], labels=['1-3', '4-7', '8-10'], right=False)

ax = sns.scatterplot(data=df, x='hour', y='dow', hue='cat', style='cat')
plt.show()

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我在另一列上绘制2列时,会绘制不同的图 - When I plot 2 columns one over the other, a different graph is plotted Python:如果数据框中的多个列具有一个特定字符串以外的任何值,则设置新的列值 - Python: Set new column value if multiple columns in a dataframe have any value other than one specific string Python:绘制数据框的直方图,其中一列作为标签,另一列作为值 - Python: Plot histogram of dataframe with one column as the labels, and the other as the values 基于一列合并 dataframe 并对其他列求和 - Python - merge a dataframe based on one column and summing the other columns - Python 在 dataframe 列上应用 function 以获得其他几个列 Pandas ZA7F5F35426B5274113ZB231 - Apply function on dataframe Column to get several other columns Pandas Python DataFrame:按一列分组并平均其他列 - DataFrame: Group by one column and average other columns Python:过滤 dataframe 行,以便值位于其他 dataframe 的列中 - Python: filter dataframe rows so that values are in columns of other dataframe 将一个 dataframe 中的一列与不同 dataframe 中的其他两列进行比较? - Compare a column in one dataframe with two other columns in a different dataframe? 如何将一个 dataframe 中的每一列与其他 dataframe 中的所有列相乘 - How to multiply every column in one dataframe with all columns in other dataframe 仅当特定列至少包含另一列的一个单词时,才从 Dataframe2 合并 Dataframe1 的 Python/Pandas 中的列 - Merge columns in Python/Pandas of Dataframe1 from Dataframe2 only if specific column contains at least one of the words of the other column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM