将大熊猫系列汇总到数据框架和视觉表示

发布于 2025-01-30 12:08:39 字数 1109 浏览 4 评论 0原文

我有三个pandas系列,称为:col_datac_pv_datac_ELEC_DATA。每个人都有以下值:

 Col_data:
 0    625814.205486
1    782267.756857
2    938721.308229
Name: 7, dtype: object
 C_PV_data:
 0    2039032.206909
1    2548790.258636
2    3058548.310363
Name: 3, dtype: object
 C_elec_data:
 0    1337523.743009
1    1671904.678761
2    2006285.614513
Name: 0, dtype: object

我想将它们汇总到单个数据框中,将数据框导出到 .xlsx 文件,其中每列称为变量。例如:

COL_DATAC_PV_DATAC_ELEC_DATA
625814.2054862039032.2069091337523.743009
782267.756857
高高614513

最后,我想用一个图形表示每个列,其中中心值为一条线,而在该线上的两个点,最低和 例如,图形将是这样的:

”在此处输入图像描述

I have three pandas Series, called: Col_data, C_PV_data and C_elec_data. Each one has these values:

 Col_data:
 0    625814.205486
1    782267.756857
2    938721.308229
Name: 7, dtype: object
 C_PV_data:
 0    2039032.206909
1    2548790.258636
2    3058548.310363
Name: 3, dtype: object
 C_elec_data:
 0    1337523.743009
1    1671904.678761
2    2006285.614513
Name: 0, dtype: object

I would like to aggregate them into a single DataFrame, to export that DataFrame to a .xlsx file, in which each column is called as the variable. For instance:

Col_dataC_PV_dataC_elec_data
625814.2054862039032.2069091337523.743009
782267.7568572548790.2586361671904.678761
938721.3082293058548.3103632006285.614513

Finally, I would like to represent each column with a graph in which the central value is a line, and two dots over that line, for the lowest and hights value. For instance, the graph would be something like this:

enter image description here

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

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

发布评论

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

评论(1

尤怨 2025-02-06 12:08:39

当然,您要去:

init

Col_data = pd.Series([
    625814.205486,
    782267.756857,
    938721.308229])
C_PV_data = pd.Series([
    2039032.206909,
    2548790.258636,
    3058548.310363])
C_elec_data = pd.Series([
    1337523.743009,
    1671904.678761,
    2006285.614513])

作为df

df = pd.concat(
    [Col_data, C_PV_data, C_elec_data], axis=1,
    keys=['Col_data', 'C_PV_data', 'C_elec_data'])
>>> df
        Col_data     C_PV_data   C_elec_data
0  625814.205486  2.039032e+06  1.337524e+06
1  782267.756857  2.548790e+06  1.671905e+06
2  938721.308229  3.058548e+06  2.006286e+06

旁注:我总是不喜欢重复。以下替代方案是干燥的(不要重复自己),但也许不清楚:

keys = ['Col_data', 'C_PV_data', 'C_elec_data']
d = locals()  # just for DRY...
df = pd.concat([d[k] for k in keys], axis=1, keys=keys)

假设

您已经安装了openpyxl已安装:

df.to_excel('foo.xlsx', index=False)

box plot

edit :(并保存保存作为PNG)

ax = df.loc[[0,1,1,1,2]].plot.box()
ax.figure.savefig('costs.png')

Sure, here you go:

Init

Col_data = pd.Series([
    625814.205486,
    782267.756857,
    938721.308229])
C_PV_data = pd.Series([
    2039032.206909,
    2548790.258636,
    3058548.310363])
C_elec_data = pd.Series([
    1337523.743009,
    1671904.678761,
    2006285.614513])

As a df

df = pd.concat(
    [Col_data, C_PV_data, C_elec_data], axis=1,
    keys=['Col_data', 'C_PV_data', 'C_elec_data'])
>>> df
        Col_data     C_PV_data   C_elec_data
0  625814.205486  2.039032e+06  1.337524e+06
1  782267.756857  2.548790e+06  1.671905e+06
2  938721.308229  3.058548e+06  2.006286e+06

Side note: I always dislike repeats. The following alternative to the above is DRY (Don't Repeat Yourself), but less clear perhaps:

keys = ['Col_data', 'C_PV_data', 'C_elec_data']
d = locals()  # just for DRY...
df = pd.concat([d[k] for k in keys], axis=1, keys=keys)

To xlsx

Assuming you have openpyxl installed:

df.to_excel('foo.xlsx', index=False)

Box plot

Edit: (and save as PNG)

ax = df.loc[[0,1,1,1,2]].plot.box()
ax.figure.savefig('costs.png')

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文