pandas-如何计算每个桑基节点的百分比
我从 splunk 导出了一些原始数据,并使用 python pandas 将原始数据转换为基于 dc、customer 和 companyID 列的源、目标和值,下面是示例数据的一部分。
dc,customer,companyID,source,target,value
我正在使用 powerBI 通过使用 networkD3 库创建 html 自定义视觉效果来显示桑基图。所以我想在本地将所有数据准备好在csv文件中,然后上传powerBI以避免在powerBI中进行任何数据计算。
那么如何通过 python pandas 计算百分比,如下图所示?基本上,源节点的百分比值应等于每个目标节点的百分比总和。
I exported some raw data from splunk, and I have transform the raw data to source, target and value based on dc, customer and companyID column by using python pandas, Below is part of sample data.
dc,customer,companyID,source,target,value
I am using powerBI to display the sankey chart by creating a html custom visual with networkD3 library. So i want to make all the data ready in a csv file locally and then upload the powerBI to avoid any data computing in powerBI.
So how to calculate the percentage by python pandas like below chart? Basically, the percentage value of the source node should be equal to the sum percentage of each target nodes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用:
输出:
Use:
output: