[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-07-22 19:42:52 +00:00
parent b957f88645
commit fb26aaf38d

View File

@ -609,7 +609,7 @@ def fill_missing_years(fill_values: pd.Series) -> pd.Series:
- The function groups the data by the 'country' level and computes the mean for each group.
- Zero values in the original Series are replaced by the mean value of their respective country group.
"""
means = fill_values.groupby(level='country').transform('mean')
means = fill_values.groupby(level="country").transform("mean")
return fill_values.where(fill_values != 0, means)
@ -686,10 +686,10 @@ def build_energy_totals(
y = to_fill.get_level_values("year")
# take total final energy consumption from Eurostat
eurostat_sector = 'Agriculture & forestry'
eurostat_sector = "Agriculture & forestry"
slicer = idx[c, y, :, :, eurostat_sector]
fill_values = eurostat.loc[slicer]["Total all products"].groupby(level=[0,1]).sum()
fill_values = eurostat.loc[slicer]["Total all products"].groupby(level=[0, 1]).sum()
# fill missing years for some countries by mean over the other years
fill_values = fill_missing_years(fill_values)
df.loc[to_fill, "total agriculture"] = fill_values
@ -698,9 +698,12 @@ def build_energy_totals(
uses = ["electricity", "heat", "machinery"]
for use in uses:
avg = (idees["total agriculture electricity"]
/idees["total agriculture"]).mean()
df.loc[to_fill, f"total agriculture {use}"] = df.loc[to_fill, "total agriculture"] * avg
avg = (
idees["total agriculture electricity"] / idees["total agriculture"]
).mean()
df.loc[to_fill, f"total agriculture {use}"] = (
df.loc[to_fill, "total agriculture"] * avg
)
# divide cooking/space/water according to averages in EU28