Skip to content

Commit

Permalink
Merge pull request #75 from statisticsnorway/extend_dato
Browse files Browse the repository at this point in the history
Extend dato
  • Loading branch information
Didrikbt authored Dec 16, 2024
2 parents 163cee4 + 71cf07c commit a48206f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
7 changes: 6 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ssb-konjunk"
version = "0.1.14"
version = "0.1.15"
description = "SSB Konjunk"
authors = ["Edvard Garmannslund <[email protected]>"]
license = "MIT"
Expand Down
11 changes: 9 additions & 2 deletions src/ssb_konjunk/statbank_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@


def format_time_period(
df: pd.DataFrame, year: int, quarter: int | str = "", col_name: str = "periode"
df: pd.DataFrame,
year: int,
quarter: int | str = "",
col_name: str = "periode",
month: int | str = "",
) -> pd.DataFrame:
"""Add column with time period.
Expand All @@ -11,12 +15,15 @@ def format_time_period(
year: the year.
quarter: optional, default ''.
col_name: optional, default 'periode'. The name of the column for the time period.
month: optional, default ''.
Returns:
pd.DataFrame: dataframe with a column with time period.
"""
if quarter != "":
if quarter != "" and month == "":
df[col_name] = f"{year}K{int(quarter)}"
elif quarter == "" and month != "":
df[col_name] = f"{year}M{int(quarter)}"
else:
df[col_name] = f"{year}"

Expand Down

0 comments on commit a48206f

Please sign in to comment.