Last active
February 9, 2021 06:07
-
-
Save Su-s/590f19489b07f3c5c2137ba855431ff4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import pandas as pd\n", | |
"import numpy as np\n", | |
"import re\n", | |
"import warnings\n", | |
"warnings.filterwarnings(\"ignore\", 'This pattern has match groups')\n", | |
"\n", | |
"\n", | |
"# Excel Files\n", | |
"vrdata = pd.read_excel('vrdata.XLSX', index_col=None)\n", | |
"forecast = pd.read_excel('Specimen GSTIN for forecast.xlsx', index_col=None)\n", | |
"\n", | |
"# Data Preprocessing\n", | |
"\n", | |
"features_vrdata = vrdata[['GSTIN No.','Name 1','Month','VR Type','Flag','Reference','VR Match code','IGST','CGST','SGST']].dropna(how = 'any').reset_index(drop = True)\n", | |
"features_forecast = forecast[['GSTIN']].reset_index(drop = True)\n", | |
"\n", | |
"features_vrdata.columns = ['GSTNO','V_NAME','MONTH','VR_TYPE','FLAG','REFERENCE','MATCH','CGST','SGST','IGST']\n", | |
"features_forecast.columns = ['GSTNO']\n", | |
"\n", | |
"\n", | |
"features_vrdata['V_NAME'] = features_vrdata['V_NAME'].map(lambda x: re.sub(r'\\W+', '', x))\n", | |
"features_vrdata['V_NAME'] = features_vrdata['V_NAME'].str.upper()\n", | |
"\n", | |
"features_vrdata['MONTH'] = pd.to_datetime(features_vrdata['MONTH'], format='%m%Y').dt.to_period('m') \n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"vr_fr = features_vrdata[features_vrdata.GSTNO != 0].reset_index(drop=True)\n", | |
"\n", | |
"vr_fr = pd.merge(features_vrdata,features_forecast[['GSTNO']],left_on=['GSTNO'],right_on=['GSTNO']).drop_duplicates().reset_index(drop=True)\n", | |
"\n", | |
"checkgstr2a = vr_fr.loc[vr_fr['VR_TYPE'] == 'GSTR2A'].reset_index(drop=True)\n", | |
"\n", | |
"checkgstr2 = vr_fr.loc[vr_fr['VR_TYPE'] == 'GSTR2'].reset_index(drop=True)\n", | |
"\n", | |
"checkgstr2a = checkgstr2a[checkgstr2a.MATCH != 0].reset_index(drop=True)\n", | |
"\n", | |
"# checkgstr2a= checkgstr2a[(checkgstr2a.FLAG == \"A\") | (checkgstr2a.FLAG == \"M\") ].reset_index(drop=True)\n", | |
"\n", | |
"checkgstr2a = checkgstr2a[['GSTNO','IGST','CGST','SGST']]\n", | |
"\n", | |
"checkgstr2a = checkgstr2a.groupby(['GSTNO'],as_index=False).sum()\n", | |
"\n", | |
"checkgstr2 = checkgstr2[['GSTNO','IGST','CGST','SGST']]\n", | |
"\n", | |
"checkgstr2 = checkgstr2.groupby(['GSTNO'],as_index=False).sum()\n", | |
"\n", | |
"merge = pd.merge(checkgstr2[['GSTNO','CGST','IGST','SGST']],checkgstr2a[['GSTNO','CGST','IGST','SGST']],on=['GSTNO'])\n", | |
"\n", | |
"merge = merge.groupby(['GSTNO'],as_index=False).sum()\n", | |
"\n", | |
"merge['GSTR2_TAX'] = merge['IGST_x']+merge['CGST_x']+merge['SGST_x']\n", | |
"\n", | |
"merge['GSTR2A_TAX'] = merge['IGST_y']+merge['CGST_y']+merge['SGST_y']\n", | |
"\n", | |
"merge['DIFF'] = abs(merge['GSTR2_TAX']-merge['GSTR2A_TAX'])\n", | |
"\n", | |
"merge['PROB'] = (1-(merge['DIFF']/merge['GSTR2_TAX']))*100\n", | |
"\n", | |
"merge = pd.merge(merge[['GSTNO','GSTR2_TAX','GSTR2A_TAX','DIFF','PROB']],features_forecast,on=['GSTNO'])\n", | |
"\n", | |
"# merge['ITC'] = merge['TAX'] * merge['PROB']/100\n", | |
"\n", | |
"merge.to_csv('TamilNaduResult.csv')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 29, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"54.01106763486345" | |
] | |
}, | |
"execution_count": 29, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"prob = merge['ITC'].sum()/merge['TAX'].sum()*100\n", | |
"\n", | |
"prob" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment