Summing Up CSV Power Plant Data By Technology And Plant Name
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
Solution 1:
With Python, you can use the 3rd party Pandas library:
Read your Excel file into a dataframe
import pandas as pd
df = 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')
Solution 2:
Pandas library will be a useful library. It is used to process data frames.
Importing Pandas Library
import pandas as pd
Reading the form csv file
df = pd.read_csv("form.csv")
Finding the sum
df.groupby('PlantName')['NameplateCapacity'].sum()
Post a Comment for "Summing Up CSV Power Plant Data By Technology And Plant Name"