Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions Financial APIs/Gross_Fiscal_Deficits EDA app/EDA app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import pandas as pd
import matplotlib.pyplot as plt
import gradio as gr
import os
import numpy as np

# Define the path to the CSV file
csv_file_path = 'Gross_Fiscal_Deficits.csv'

def visualize_eda(start_date, end_date):
# Create a directory to save plots
if not os.path.exists('eda_plots'):
os.makedirs('eda_plots')

# Initialize output paths
line_plot_path = 'eda_plots/line_plot.png'
bar_plot_path = 'eda_plots/bar_plot.png'
hist_plot_path = 'eda_plots/hist_plot.png'
scatter_plot_path = 'eda_plots/scatter_plot.png'

# Load the data from the CSV file
try:
df = pd.read_csv(csv_file_path, parse_dates=True, index_col=0)
except Exception as e:
return [None, None, None, None, f"Error loading CSV file: {e}"]

# Filter the data by the given date range
try:
df = df.loc[start_date:end_date]
except Exception as e:
return [None, None, None, None, f"Error filtering data: {e}"]

# Check for and handle non-numeric columns
df_numeric = df.select_dtypes(include=['float64', 'int64'])
if df_numeric.empty:
return [None, None, None, None, "Error: No numeric data found in CSV file."]

# Plot 1: Line plot of all numerical features
try:
plt.figure(figsize=(12, 6))
for column in df_numeric.columns:
plt.plot(df_numeric.index, df_numeric[column], label=column)
plt.title('Line Plot of Numerical Features')
plt.xlabel('Date')
plt.ylabel('Value')
plt.legend()
plt.savefig(line_plot_path)
plt.close()
except Exception as e:
return [None, None, None, None, f"Error generating line plot: {e}"]

# Plot 2: Bar plot of average values per month
try:
plt.figure(figsize=(12, 6))
monthly_avg = df_numeric.resample('M').mean()
monthly_avg.plot(kind='bar', figsize=(15, 7))
plt.title('Monthly Average of Numerical Features')
plt.xlabel('Month')
plt.ylabel('Average Value')
plt.savefig(bar_plot_path)
plt.close()
except Exception as e:
return [None, None, None, None, f"Error generating bar plot: {e}"]

# Plot 3: Histogram of numerical features
try:
plt.figure(figsize=(12, 6))
df_numeric.hist(bins=30, figsize=(15, 7))
plt.suptitle('Histogram of Numerical Features')
plt.savefig(hist_plot_path)
plt.close()
except Exception as e:
return [None, None, None, None, f"Error generating histogram: {e}"]

# Plot 4: Scatter plot matrix of numerical features
try:
from pandas.plotting import scatter_matrix
plt.figure(figsize=(12, 12))
scatter_matrix(df_numeric, alpha=0.2, figsize=(15, 15), diagonal='kde')
plt.suptitle('Scatter Plot Matrix of Numerical Features')
plt.savefig(scatter_plot_path)
plt.close()
except Exception as e:
return [None, None, None, None, f"Error generating scatter plot matrix: {e}"]

# Return paths to generated plots
return [line_plot_path, bar_plot_path, hist_plot_path, scatter_plot_path, None]

# Define the Gradio interface
iface = gr.Interface(
fn=visualize_eda,
inputs=[
gr.Textbox(label="Start Date (YYYY-MM-DD)", value="2002-01-02"),
gr.Textbox(label="End Date (YYYY-MM-DD)", value="2022-10-10")
],
outputs=[
gr.Image(type="filepath", label="Line Plot"),
gr.Image(type="filepath", label="Bar Plot"),
gr.Image(type="filepath", label="Histogram"),
gr.Image(type="filepath", label="Scatter Plot Matrix"),
gr.Textbox(label="Error Message", type="text") # Add a textbox for error messages
],
live=False # This will add an explicit "Submit" button
)

# Launch the Gradio app
iface.launch(share=True, inbrowser=True)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Year,1980-81,1981-82,1982-83,1983-84,1984-85,1985-86,1986-87,1987-88,1988-89,1989-90,1990-91,1991-92,1992-93,1993-94,1994-95,1995-96,1996-97,1997-98,1998-99,1999-00,2000-01,2001-02,2002-03,2003-04,2004-05,2005-06,2006-07,2007-08,2008-09,2009-10,2010-11,2011-12,2012-13,2013-14,2014-15 (RE),2015-16 (BE)
Andhra Pradesh ,222.1,243.7,172.4,493,591.4,435,804,568,673,972,967.1,1125.3,1569.3,1833.2,2348.5,2416.8,2811.5,2427.8,5705.6,4976.4,7305.9,6723.1,7630,7450,8190,8300,5640,8790,12410,14010,11800,15400,17510,18040,20320,17580
Arunachal Pradesh,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,23,38,1,75,25.8,-20.3,-9.3,16.1,73.2,39.8,70.1,121,55.4,59.3,210.1,274.7,210,250,390,260,-110,-20,330,500,-10,990,230,1610,3560,510
Assam,-27.4,171.7,200.1,327.2,366.6,154,243,421,303,528,567.5,254.7,208.1,-17.9,710.6,652.2,73.8,142.1,338.2,1605.8,1540,1448.1,930,1390,2060,-360,-710,-790,-1410,4040,1990,1650,1520,3780,16260,4680
Bihar,335.8,409.1,434.7,328,395.9,326,461,825,535,994,1594.6,1617,1330.9,1339.3,1342.1,1570.6,890.6,981.4,2378.9,6107.7,4884.3,4010.3,4910,4110,1240,3700,3020,1710,2510,5270,3970,5910,6550,8350,32820,13580
Chhattisgarh,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,-47.5,1060.7,970,2200,1230,430,-30,130,1030,1760,-410,800,2660,5060,5770,6840
Goa,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,61,72,64,95,96.1,125.3,90.3,59.6,44.5,97.3,104,124.6,269.1,341,412.9,412.8,380,450,550,600,490,540,810,1240,570,880,1150,1350,1740,2710
Gujarat,246.5,253.9,376.6,397.6,520.2,514,900,976,735,952,1798.2,1875.7,1173.6,526.4,1292.4,1745.6,2358.3,3174.5,5619,6792,7987.6,6510.8,6080,9160,8700,6270,5650,4770,10440,15150,15070,11030,16490,18420,18380,22050
Haryana,112,101.6,188.6,133.7,234.8,230,170,216,289,393,385.7,374.7,444.1,479.9,534.6,986,1099.4,1127.6,2240.4,2132.5,2265.2,2739.6,1470,2930,1210,290,-1180,1260,6560,10090,7260,7150,10360,8310,15630,16420
Himachal Pradesh,-34.9,56.6,74.1,57.9,79.5,35,89,129,254,226,278.6,223.8,311.5,152.1,620.4,521.4,572,1202.2,1661.5,189.6,1844.8,1511.3,2340,2380,1810,720,920,550,2280,2780,1830,1630,2980,4010,3830,3280
Jammu & Kashmir,144.5,135.9,142,198.3,248.2,247,244,417,410,524,661.2,448.7,203.5,87.7,-23.4,96.6,166.2,443.6,1054.4,1338.6,2166.4,748.1,1250,-20,1010,1590,1460,2610,2330,2230,2370,3690,4220,4550,6630,6630
Jharkhand,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,1642.7,2190,1660,3650,4920,5260,6220,3750,1780,4840,1930,3400,2220,4910,5160
Karnataka,225.9,118,279.9,287.7,563.3,550,514,518,497,625,558.5,917.8,1386,1254,1512.9,1456.8,1944,1609.8,3112.1,4276.5,4219.2,5869.9,5280,4500,3600,3690,4690,5330,8730,10870,10690,12300,14510,17090,19030,20220
Kerala,179.8,61.7,122.9,299.3,232.3,323,440,448,412,604,798.5,803.4,732,935.2,1108.7,1302.7,1542.5,2413.9,3012.2,4536.6,3877.8,3269.4,4990,5540,4450,4180,3820,6100,6350,7870,7730,12810,15000,16940,16000,17700
Madhya Pradesh,337.2,237.5,290.5,366.4,494.2,516,561,725,871,723,1019.3,984,876.3,982.5,1416.9,1633.4,1926.3,1820.6,4126.7,3911.4,2712.1,3649.4,4060,7320,6490,4570,2750,2780,4430,6200,5270,5760,9420,9880,13570,16750
Maharashtra,463.3,488.5,551.5,739.7,1050.5,1234,1065,1014,1277,1844,1610.9,1656.9,2585.6,2265.3,2861.4,4150.8,4953.7,6442.2,7462.4,11706.2,8975.8,10897.7,14290,17930,18620,17630,11550,-2820,14000,26160,18860,19970,13740,26020,37250,30730
Manipur,-6.7,27.1,17.4,26.2,14.5,-9,32,17,33,71,39.6,69.1,18.2,-20.4,62.1,104.7,167.5,187.5,106.2,655.8,234.4,340.3,250,290,450,270,480,-100,220,730,570,1050,0,-270,930,580
Meghalaya,-7.7,16.5,15.1,10,2,-8,5,1.5,10,31,41.2,72.2,93.1,87.6,35.3,51.9,23.1,126.5,147.3,209.1,249.6,220.9,160,200,310,180,80,210,440,230,340,1070,400,380,530,820
Mizoram,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,41,-22,102,11,-3,-94.4,4.8,59.5,7.6,38.4,70.7,125.3,124.2,132.3,179.1,375.3,422.4,320,310,230,400,190,390,90,310,650,210,580,750,2000,110
Nagaland,-26.3,20.1,29.5,41,-4.6,-12,30,60,48,141,101.9,95.7,138.2,174.2,238.8,231,184.2,203.9,243.2,249,358.8,366.1,440,-160,220,310,160,400,340,520,310,540,650,460,850,1160
Odisha,134.1,141.8,212.2,191.6,328.4,326,372,506,550,574,616.2,913.2,740.1,901.5,1158.9,1395.9,1602,1802.5,2915.5,3746.1,3325.3,3964.2,2820,3570,1370,280,-820,-1320,330,2270,660,-620,0,4630,9140,10400
Punjab,159.8,178.3,182.8,262.1,479.2,566,343,968,833,909,1242.2,1150.5,1252,1493.4,1785.2,1364.6,1464.7,2477.6,3779.3,3194.7,3903.8,4958,4400,4880,4040,2660,4380,4600,6690,6170,7140,8490,9350,8790,10400,11900
Rajasthan,206.7,326.5,274.9,297.5,362.7,343,467,903,736,581,544.8,792.4,1158.7,1470,1762.7,2574.3,2506.5,2552,5150.9,5361.2,4313.2,5748.4,6110,7370,6150,5150,3970,3410,6970,10300,4130,3630,8530,15190,23160,20610
Sikkim,5.6,4.8,-1.8,6.9,-2.8,12,1,9,11,30,20.2,41.1,34.1,30.7,45.7,40.1,55.9,66.9,146.9,92.6,50.5,66.8,10,50,190,150,100,60,230,170,320,180,70,50,450,520
Tamil Nadu,210.4,212.5,326.1,363.6,397.7,365,454,660,654,919,1126.3,1299.9,1749.1,1357.6,1496.4,1255.9,2445,2121.7,4777.1,5382.3,5076,4739.4,6740,5590,5570,2250,3960,3690,8550,11810,16650,17270,16520,20580,27350,31830
Telangana,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0,17400,16970
Tripura,-9.1,24.8,17.1,34.9,12.4,15,15,62,84,89,85.6,93.9,23,111,110,33.9,121.7,195.8,118.4,290.3,445.2,538.2,540,340,240,110,-130,20,270,-70,250,-260,-340,-50,1320,1940
Uttar Pradesh,551.4,452,581.7,1082.3,1493.6,1058,1410,1014,1802,2482,3067.6,2836.6,3710.9,3165.8,4766.5,4380.6,5956.2,7576,11632.5,11098.7,10179.5,9898.1,9500,16650,13000,10080,9620,13790,20510,18690,17250,15430,19240,23680,28380,31560
Uttarakhand,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,136.4,424.2,890,1410,2170,1880,890,1740,1840,2780,1840,1760,1600,2650,3970,4100
West Bengal,289.2,380.1,497.8,413.9,339.7,259,587,551,579,1055,1633.7,1143.7,1012.5,1671.9,1965.3,2696.3,3396.9,4007.7,7109.1,11666.4,10920.2,11804.1,10570,12870,10650,9600,11430,11400,13560,24950,19530,17700,19150,25350,23880,15980
Delhi,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,231.7,388.9,555.9,690,726.4,959.2,1381.6,1609.7,1733,2400,2440,1480,-250,410,2040,2820,3550,-730,2550,2280,3940,350,420
Puducherry,,,,,,,,,,,,,,,,,,,,,,,,,,280,400,330,370,580,710,820,220,540,550,610
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions Financial APIs/Gross_Fiscal_Deficits EDA app/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@


# stocks Visualization App

<img width="1599" alt="Screenshot 2024-08-03 at 1 29 46β€―AM" src="https://github.com/user-attachments/assets/b395de2a-4fab-4fae-b390-b8ec8b82cc2a">



This application provides interactive visualizations of numerical data from a CSV file using Gradio. The application allows users to view line plots and bar charts for the specified date range.

## Features
- **Line Plot**: Displays trends for all numerical features over time.
- **Bar Plot**: Shows the average values of numerical features per month.

## Requirements
- Python 3.x
- `pandas`
- `matplotlib`
- `gradio`

You can install the required packages using:
```bash
pip install pandas matplotlib gradio
```

## Usage
1. **Prepare Your Data**: Ensure your CSV file is in the same directory as this script. The CSV should have a date column as the index and numerical columns for plotting.

2. **Run the App**: Execute the script to launch the Gradio interface:
```bash
python your_script_name.py
```
Replace `your_script_name.py` with the name of your Python script.

3. **Interact with the App**:
- Enter the **Start Date** and **End Date** in the format `YYYY-MM-DD`.
- Click **Submit** to generate the plots.
- View the generated **Line Plot** and **Bar Plot**.

## Example
For a CSV file with the following columns: `Date`, `Feature1`, `Feature2`, the app will generate:
- **Line Plot**: Trends of `Feature1` and `Feature2` over the selected date range.
- **Bar Plot**: Monthly averages of `Feature1` and `Feature2`.

## Troubleshooting
- **No Numeric Data Error**: Ensure your CSV contains numeric data and the index column is of date type.
- **Plot Generation Error**: Check if the date range covers the data present in the CSV file.

## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

---

Feel free to adjust the content as needed!