Summing up CSV power plant data by technology and plant name

2024/10/11 20:27:17

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.

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,..

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.

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

Answer

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

Read your Excel file into a dataframe

import pandas as pddf = pd.read_excel('file_in.xlsx')

Calculate GroupBy with sum

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()

We use reset_index to return a dataframe.

Export back to Excel

res.to_excel('file_out.xlsx')
https://en.xdnf.cn/q/118285.html

Related Q&A

Send and receive signals from another class pyqt

I am needing a way to receive signals sent by a Class to another class. I have 2 classes: In my first class I have a function that emits a signal called asignal In my second class I call the first cla…

I can not add many values in one function

I have a gui applicationI put text into text box1, text box2,………… text box70 ,and then click on the pushButton, The function return_text () in the module_b.py be called. Now I can call one instance…

Close browser popup in Selenium Python

I am scraping a page using Selenium, Python. On opening the page one Popup appears. I want to close this popup anyway. I tried as below:url = https://shopping.rochebros.com/shop/categories/37browser = …

How can I replace certain string in a string in Python?

I am trying to write two procedures to replace matched strings in a string in python. And I have to write two procedures. def matched_case(old new): .........note: inputs are two strings, it returns a…

Python: `paste multiple (unknown) csvs together

What I am essentially looking for is the `paste command in bash, but in Python2. Suppose I have a csv file:a1,b1,c1,d1 a2,b2,c2,d2 a3,b3,c3,d3And another such:e1,f1 e2,f2 e3,f3I want to pull them toget…

Django Redirect after Login Error

Im new to Django and I know that to redirect after login I have to set the parameter page. But this only works when the login is successful. How can i do the same thing when some error occurs?? Ps: I…

Python: Pulling .png from a website, outputting to another

Hoping this question is not too vague, or asking for too much. Essentially I am analyzing large amounts of spectra, and wanting to create one large webpage that contains these spectra rather than looki…

Using peakutils - Detecting dull peaks

Im currently using peakutils to find peaks in some data. My data contains some "dull peaks", that is my peaks plateau somewhat. I cant set my code to find these peaks even after playing aroun…

nonlinear scaling image in figure axis matplotlib

enter image description hereI hope I have not over-looked as previously asked question. I dont think so. I have an image of a spectrum. I have several laser lines for calibration. Since the laser li…

How to correctly call a git submodule symlinked?

On the Sublime Text Package Control issue:Why ignore VCS-based packages accordingly to this message? I find out what causes this error. I had the package All Autocomplete triggering it. Then I gone to…