Showing posts with label Programming Languages. Show all posts
Showing posts with label Programming Languages. Show all posts

Thursday, August 14, 2025

Import Macro Data from MOSPI into Python:

 Step 1 — Capture the Download URL (One-Time Setup)

  1. Open the MOSPI page: https://esankhyiki.mospi.gov.in/

  2. Search for your dataset (CPI, WPI, IIP, etc.)

  3. Press F12 → Network tab and tick Preserve log

  4. Click the Download button on the page

  5. In the network log, find the .xlsx request (e.g., cpi_8.xlsx) and copy the Request URL

 Step 1 — Python Automation and Data Processing

# CPI Python Code can be copied directly

url = "https://api.mospi.gov.in/api/download/CPI/cpi_8.xlsx"

output_file = "cpi_8.xlsx"


response = requests.get(url)

response.raise_for_status()  # Check for errors


with open(output_file, "wb") as f:

    f.write(response.content)


Ind_CPI = pd.read_excel("cpi_8.xlsx")


Ind_CPI['month_end'] = pd.to_datetime(

    Ind_CPI['year'].astype(str) + '-' + Ind_CPI['month_code'].replace(0, 12).astype(str) + '-01'

) + pd.offsets.MonthEnd(0)



Ind_CPI = (

    Ind_CPI

    .groupby(['month_end', 'group'], as_index=False)['index']

    .mean()

)


Ind_CPI = Ind_CPI.pivot(index='month_end', columns='group', values='index')

Ind_CPI = Ind_CPI.reset_index()


Ind_CPI['Quarter_End'] = pd.to_datetime(Ind_CPI['month_end']) + pd.offsets.QuarterEnd(0)

Ind_CPI = Ind_CPI.drop(columns=['month_end'])


Ind_CPI_qtr = (

    Ind_CPI

    .groupby('Quarter_End', as_index=False)

    .mean(numeric_only=True)  # averages each subgroup's monthly values into quarterly

)


Ind_CPI_qtr_pc = Ind_CPI_qtr.copy()

Ind_CPI_qtr_pc.iloc[:, 1:] = Ind_CPI_qtr_pc.iloc[:, 1:].pct_change(periods=x)  # in %



Ind_CPI_qtr_pc = Ind_CPI_qtr_pc.dropna().reset_index(drop=True)


Ind_CPI_qtr_pc['Quarter_End'] = Ind_CPI_qtr_pc['Quarter_End'].dt.date

Tuesday, June 13, 2017

SQL Basic Queries and Quick References Tutorial



1- Creating Table
2-  Basic Queries
3- Key Words
4- Scalar Value Functions
5- String
6- Constraints
7- Joins
8- Sub-Queries
9- Analytical Functions
10- Table and Table Variables
11- Transaction Control
12- Stored Procedures
13- User Defined Functions
14- Triggers
15- Performance Tunning.



https://drive.google.com/file/d/0Bx3mfFH5R-y3WG9fdnZvR2J2cmM/view?usp=sharing

R3 chase - Pursuit

Import Macro Data from MOSPI into Python:

  Step 1 — Capture the Download URL (One-Time Setup) Open the MOSPI page: https://esankhyiki.mospi.gov.in/ Search for your dataset (CP...