Python:在条形图中显示列中的值数

发布于 2025-02-07 06:08:43 字数 1057 浏览 2 评论 0原文

在下面的数据框中,每列具有“相等”值。我需要一个条形图,该图显示了其中有多少个相对于列的值。 X平面上的列名和Y平面上的“相等”的总数。不幸的是,我无法显示它,因为我无法打印它。谢谢。

   result_invoiceNo result_totalGross  ... result_totalNet result_invoiceDate
0              equal             equal  ...           equal              equal
1                                       ...                                   
2              equal             equal  ...           equal              equal
3                                       ...                                   
4              equal             equal  ...           equal              equal
..               ...               ...  ...             ...                ...
183                                     ...                          not equal
184            equal             equal  ...           equal              equal
185                                     ...                                   
186            equal             equal  ...           equal              equal
                                                                

In the dataframe below, each column has an "equal" value. I need a bar graph that shows how many of these values are relative to the columns. Column names on the x plane and the total number of "equal" on the y plane. Unfortunately, I can't show it because I can't print it. thanks.

   result_invoiceNo result_totalGross  ... result_totalNet result_invoiceDate
0              equal             equal  ...           equal              equal
1                                       ...                                   
2              equal             equal  ...           equal              equal
3                                       ...                                   
4              equal             equal  ...           equal              equal
..               ...               ...  ...             ...                ...
183                                     ...                          not equal
184            equal             equal  ...           equal              equal
185                                     ...                                   
186            equal             equal  ...           equal              equal
                                                                

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

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

发布评论

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

评论(1

笑叹一世浮沉 2025-02-14 06:08:43

CSV **,
如果所有数据帧的所有列都包含在“相等”或“不相等”的数据中,那么我已经解决了您的上述问题并找到了解决方案。那是下面的。

import pandas as pd

#create a DataFrame 
dt_frame = pd.DataFrame({'Column_A':['equal','equal','not equal','equal','equal','equal','equal','equal','not equal','equal'],
                        'Column_B':['not equal','equal','equal','equal','not equal','equal','equal','equal','not equal','equal'],
                        'Column_C':['equal','equal','equal','equal','equal','not equal','equal','equal','not equal','equal']})

#review the DataFrame
dt_frame.head()

head()默认情况下返回DataFrame的前五个元素。
<

columns = dt_frame.columns  # list of the columns of dataframe
# creating a new dataframe with two columns one is 'equal' and second is 'not equal' with columns as index.
pd_dt = pd.DataFrame({'equal':[None],'not equal':[None]}, index=columns)
pd_dt  #review the new dataframe.

pd_dt

现在,计数来自dt_frame的每一列中的值,并将计数放入pd_dt列中。

for c in columns:
    pd_dt.loc[c]=dt_frame[c].value_counts()
pd_dt  # review the again dataframe.

最终pd_dt
现在,绘制 bar 图,PANDA提供了绘制数据框架的绘图函数。

pd_dt.plot(kind='bar', figsize=(10,10))

输出

csv**,
I have gone through your above question and got the solution for it, if all the columns of dataframe is contains with 'equal' or 'not equal' data. that is below.

import pandas as pd

#create a DataFrame 
dt_frame = pd.DataFrame({'Column_A':['equal','equal','not equal','equal','equal','equal','equal','equal','not equal','equal'],
                        'Column_B':['not equal','equal','equal','equal','not equal','equal','equal','equal','not equal','equal'],
                        'Column_C':['equal','equal','equal','equal','equal','not equal','equal','equal','not equal','equal']})

#review the DataFrame
dt_frame.head()

head() returns the top five elements from DataFrame by default.
Top 5 records of dt_frame

Convert your dataframe into below as well as.

columns = dt_frame.columns  # list of the columns of dataframe
# creating a new dataframe with two columns one is 'equal' and second is 'not equal' with columns as index.
pd_dt = pd.DataFrame({'equal':[None],'not equal':[None]}, index=columns)
pd_dt  #review the new dataframe.

pd_dt

Now count the values from every column of dt_frame and put the count in pd_dt columns.

for c in columns:
    pd_dt.loc[c]=dt_frame[c].value_counts()
pd_dt  # review the again dataframe.

final pd_dt
Now, plot the bar graph, pandas provides the plot function to plot the dataframe.

pd_dt.plot(kind='bar', figsize=(10,10))

Output
bar graph of dataframe

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