diff --git a/NOTEBOOKS/04_API_LAYER_ETL/01_API.ipynb b/NOTEBOOKS/04_API_LAYER_ETL/01_API.ipynb index 93d57239..5b2e5c2f 100644 --- a/NOTEBOOKS/04_API_LAYER_ETL/01_API.ipynb +++ b/NOTEBOOKS/04_API_LAYER_ETL/01_API.ipynb @@ -410,8 +410,22 @@ "df_dividend = pd.read_csv(dividend_gold_file_path)\n", "print(f\"Proccessing Data : {dividend_gold_file_path}\")\n", "\n", - "# Convert 'date' to datetime and extract year\n", - "df_dividend[\"year\"] = pd.to_datetime(df_dividend[\"date\"]).dt.year\n", + "# Convert 'date' column to datetime if not already in datetime format\n", + "df_dividend['date1'] = pd.to_datetime(df_dividend['date'])\n", + "\n", + "# Function to calculate financial year\n", + "def get_financial_year(date):\n", + " year = date.year\n", + " if date.month < 4: # If month is before April, it belongs to the previous financial year\n", + " start_year = year - 1\n", + " end_year = year\n", + " else:\n", + " start_year = year\n", + " end_year = year + 1\n", + " return f\"{start_year}-{str(end_year)[-2:]}\" # Format as 'YYYY-YY'\n", + "\n", + "# Apply the function to create the 'financial_year' column\n", + "df_dividend['year'] = df_dividend['date1'].apply(get_financial_year)\n", "\n", "stock_wise_dividend_data = [\n", " {\n", @@ -531,7 +545,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.4" + "version": "3.11.6" } }, "nbformat": 4,