在Excel中绘制各种列

发布于 2025-01-31 18:03:31 字数 207 浏览 1 评论 0原文

我有一个带有几列的Excel文件。 在此列中,我想绘制具有这样的名称的列: ivof_1_h,ivof_1_l,ivof_2_h,ivof_2_l,...这些列将在y轴上。 相同

对于X轴,列将始终与我不知道文件中有多少列 。我只知道这个数字正在增加。是否有可能检查我拥有多少个IVOF列并绘制它们的可能性。

通常,这些IVOF列有一个限制如果缺少这些列之一,代码将崩溃。

I have an Excel file with several columns.
From this columns I want to plot columns which have a name like this:
IVOF_1_H, IVOF_1_L, IVOF_2_H, IVOF_2_L,...those columns will be on y axis. For the x axis the column will always be the same

I do not know how many of those columns I have in the file. I only know that the number is increasing. Is there any possibility to check how many of those IVOF columns I have and plot them.

In general, there is a limitation of those IVOF columns and I don't mind to set up my script in a way that all of those columns got plotted (if they are existing), but then I don't know how to avoid the code to crash if one of those columns is missing.

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

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

发布评论

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

评论(1

沧桑㈠ 2025-02-07 18:03:31

您可以通过其列名过滤数据框:

import pandas as pd

df = pd.read_excel('sample.xlsx')
df = df.filter(regex=("IVOF.*"))
#plot the first row
df.iloc[0].plot(kind="bar")
#plot all rows
df.plot(kind="bar")

简单示例:

import pandas as pd
import numpy as np

df =  pd.DataFrame(np.array([[2,4,4],[4,3,3],[5,9,1]]),columns=['A','B1','B2'])
df = df.filter(regex=("B.*"))
df.plot(kind="bar")

结果:

”在此处输入图像描述”

You can filter your data frame by its column name:

import pandas as pd

df = pd.read_excel('sample.xlsx')
df = df.filter(regex=("IVOF.*"))
#plot the first row
df.iloc[0].plot(kind="bar")
#plot all rows
df.plot(kind="bar")

simple example:

import pandas as pd
import numpy as np

df =  pd.DataFrame(np.array([[2,4,4],[4,3,3],[5,9,1]]),columns=['A','B1','B2'])
df = df.filter(regex=("B.*"))
df.plot(kind="bar")

The result:

enter image description here

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