I am trying to achieve the simplest task - creating the FISCAL_YEAR column as shown below (column YEAR is given):
+------+-------------+
| YEAR | FISCAL_YEAR |
+------+-------------+
| 2022 | 2022-2023 |
+------+-------------+
| 2022 | 2022-2023 |
+------+-------------+
| 2022 | 2022-2023 |
+------+-------------+
| 2022 | 2022-2023 |
+------+-------------+
I keep getting the error: can only concatenate str (not "int") to str
These are the steps I've tried so far, without success:
df['fiscal_year'] = str(df['year']) + "-" + str(df['year']+1)
df['fiscal_year'] = df['year'].astype(str) + "-" + (df['year']+1).astype(str)
df['year_str'] = pd.Series(df['year'], dtype=pd.StringDtype())
And also:
df['year_str'] = df['year'].astype(str)
And then:
df['year_str'].str.cat(df['year_str'].astype(int) + 1, sep='-')
None of these options work. Is there is anything else I'm missing?
** I am on Windows 10 and Python version 3.9.7