从python中的数据帧创建散点图

发布于 2025-01-22 06:40:36 字数 656 浏览 1 评论 0原文

我正在尝试从数据框架中创建一个散点图,但是我只能通过一些修改来实现它,而我无法使它起作用。

我的数据框如下。

1S2S1分钟
1月2日1月2日0.10.40.3
1月18日180.20.2 0.20.2 0.2
1月1日180.30.20.1

我想创建的是每个时间间隔(sec/min)平均时间间隔的平均散点图。

在我的数据范围内,我的时间间隔最高30分钟。

我知道我可以将平均值添加到另一个数据框架中,并在分钟内分别调整时间间隔,但是是否有一种较短的方法可以做到这一点,而不是硬编码变量?

我假设.mean()将计算满足第一个条件的列均值,但是我不确定将minuets转换为plt.scatter()代码中的秒数的简短方法。

事先感谢您的任何帮助。

I am attempting to create a scatter plot from a data frame which alone I can do however with some modifications I cannot get it to work.

my data frame is as follows.

1s2s1min
2 Jan 180.10.40.3
3 Jan 180.20.30.2
4 Jan 180.30.20.1

What I would like to create is a scatter plot of the average of each time interval (sec/min) plotted against the time interval in seconds.

In my data frame I have time intervals up to 30mins.

I know I could add the mean to another data frame and adjust the time intervals in mins to seconds separately, however is there a shorter way to do this that's not hardcoding variables?

I assume that .mean() will calculate the column means which satisfies the first condition but I am unsure of a short way to convert the minuets to seconds within the plt.scatter() code.

Thanks in advance for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

金橙橙 2025-01-29 06:40:36

我找到了解决方案;

Xav = dataframe.mean() #to get the mean across the days 

Xav.index
time = [0] +[pd.Timedelta(x).total_seconds() for x in Xav.index[1:]]
#to convert the columns into seconds 

fig, axes = plt.subplots(nrows=1,ncols=0,figsize=(20,4))
sns.scatterplot(x=time,y=Xav,ax=axes[0])
axes[0].set_xlabel('Sampling frequency (secs)')
axes[0].set_ylabel('Averaged X')

I have found a solution;

Xav = dataframe.mean() #to get the mean across the days 

Xav.index
time = [0] +[pd.Timedelta(x).total_seconds() for x in Xav.index[1:]]
#to convert the columns into seconds 

fig, axes = plt.subplots(nrows=1,ncols=0,figsize=(20,4))
sns.scatterplot(x=time,y=Xav,ax=axes[0])
axes[0].set_xlabel('Sampling frequency (secs)')
axes[0].set_ylabel('Averaged X')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文