按技术和工厂名称汇总CSV电厂数据 [英] Summing up CSV power plant data by technology and plant name

查看:104
本文介绍了按技术和工厂名称汇总CSV电厂数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对有关美国权力的表格860 有疑问植物.

I've got a question regarding the Form 860 data about US power plants.

它是按块而不是按工厂组织的.为了变得有用,必须对容量数字求和.

It is organized block-wise and not plant-wise. To become useful, the capacity numbers must be summed up.

如何获得每个工厂的每种技术的总产能(按名称或ID)?

How may I get the total capacity for each technology for each plant (by name or id)?

Plant ID,Plant Name,Nameplate Capacity (MW),Technology,...
3,Barry,153.1,Natural Gas Steam Turbine,..
3,Barry,153.1,Natural Gas Steam Turbine,..
3,Barry,403.7,Conventional Steam Coal,..
3,Barry,788.8,Conventional Steam Coal,..
3,Barry,195.2,Natural Gas Fired Combined Cycle,..
3,Barry,195.2,Natural Gas Fired Combined Cycle,..
10,Greene County,299.2,Natural Gas Steam Turbine,..
10,Greene County,269.2,Natural Gas Steam Turbine,..
10,Greene County,80,Natural Gas Fired Combustion Turbine,..
10,Greene County,80,Natural Gas Fired Combustion Turbine,..
10,Greene County,80,Natural Gas Fired Combustion Turbine,..

在Calc或Excel中,仅使用SUMIF进行总结很容易,但是如何通过技术进行过滤? 因此,我最好要通过纯CSV处理来做到这一点.

Only summing up is easily doable with SUMIF in Calc or Excel, but how to filter by technology? So I've better wanted to do this by pure CSV processing.

例如Python?谢谢您的答复!

Is this possible with e.g. Python? Thanks for any good answer!

推荐答案

使用Python,您可以使用第三方Pandas库:

With Python, you can use the 3rd party Pandas library:

将Excel文件读入数据框

import pandas as pd

df = pd.read_excel('file_in.xlsx')

使用总和计算GroupBy

Grouper键可以是标量或列表.例如,它们都有效:

Grouper key(s) may either be a scalar or a list. For example, these are both valid:

res = df.groupby('Technology')['Capacity'].sum().reset_index()
res = df.groupby(['ID', 'Name'])['Capacity'].sum().reset_index()

我们使用reset_index返回一个数据帧.

We use reset_index to return a dataframe.

导出回Excel

res.to_excel('file_out.xlsx')

这篇关于按技术和工厂名称汇总CSV电厂数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆