Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

here. is my Revenue_Deficits EDA app #979

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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/Revenue_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 = 'Revenue_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)
32 changes: 32 additions & 0 deletions Financial APIs/Revenue_Deficits EDA app/Revenue_Deficits.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
State,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,2015-16 (RE)
Andhra Pradesh ,-104,-80,-132.6,88.6,169,7.3,189,-37,-33,238.2,157.6,169.6,123.8,-232.3,727.8,738.9,3199.1,703.2,2684.1,1233.3,3595.1,2881.3,3054,2962,2558,64,-2807,-159,-1000,-1230,-2460,-3140,-1130,-340,14240,7300
Arunachal Pradesh,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,-39,-50,-93,-31.6,-100.1,-158.2,-163.2,-147.5,-166.6,-246.5,-206.7,-172.3,-177.1,-199,-51.9,-28,-77,-184,8,-182,-695,-743,-980,-600,-1680,-1080,-980,-90,1210,-2330
Assam,-165,36.8,43.9,137.2,135.8,5.6,-61,84,62.1,136.7,143.8,-269.7,-162.3,-416.3,309.3,200,-284.5,-287.1,-90.2,1004.7,779.5,881.4,319,685,292,-1509,-2210,-2581,-3830,1350,-50,-930,-1550,-240,5090,-5500
Bihar,-59,7,37.7,-72.1,-106.7,-297.7,-346,-190,-277.5,34,566.1,885,606,689.5,933.4,1078.9,216,263.9,1350.5,3549.7,2960.7,2341.9,2457,1107,-1076,-81,-2498,-4645,-4470,-2940,-6320,-4820,-5100,-6440,4510,-11980
Chhattisgarh,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,-271.1,538.4,113,641,-146,-1381,-2647,-3039,-1870,-890,-3360,-3240,-2610,810,-2380,-4230
Goa,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,1,7,-12,11,-7.2,9.5,-8.5,-33.2,-56.2,-32.9,-21.5,14.1,140.8,208.9,226,228.5,167,140,123,22,-141,-166,-100,130,-660,-300,220,350,-50,-410
Gujarat,-122,-120.3,-66.3,-139,-68.3,70,309,286,126.7,126,702.7,575.6,299.8,-96.2,-262.2,222,591.4,1017.8,2863.4,3616.8,6302.2,6731.5,3565,3707,4037,399,-1770,-2150,70,6970,5080,-3210,-5570,-4720,-6390,-7310
Haryana,-59,-50.5,-44.8,-75.9,-29.6,-106.1,-163,-17,1.9,95,19.7,32.2,1.7,-80.5,390.5,346.8,718.7,719.4,1540.2,1185.3,607.5,1056,685,274,258,-1213,-1590,-2224,2080,4260,2750,1460,4440,3880,9500,9560
Himachal Pradesh,-104,-21.8,-9.1,-32.7,-37.6,-107.8,-70,-41,69.8,61,94.8,-9.9,93.1,-113.6,307.9,150.3,154.9,528.7,1022.3,106.3,1330.6,860.5,1482,1607,1158,-92,-191,-850,130,800,540,-640,580,1640,1540,-50
Jammu & Kashmir,15,-2.3,1,46.5,70.9,-6.6,-42,107,63.9,123,91.2,-104,-267,-459,-702.5,-740.7,-791.6,-808,400.2,541.6,1258.6,-735.5,-652,-1910,-1577,-1816,-1914,-2216,-3360,-4450,-3770,-2100,-1100,-70,-3490,-3100
Jharkhand,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,p,331,-142,1111,1553,1090,1484,-630,-2610,140,-1430,-1370,-2710,-3830,-4680
Karnataka,-59,-164.3,-41.9,-72.9,143.6,84.7,-79,110,38.7,147,78.9,178.7,170,-116.4,296.2,-62.3,578.9,276.8,1215.2,2325.3,1862.2,3284.5,2646,525,-1638,-2311,-4152,-3776,-1630,-1620,-4170,-4690,-1880,-350,-160,-910
Kerala,28,-96,-26.8,58.2,13.7,74.2,152,195,163.9,250,422,364.3,337.4,371.3,399.9,402.8,643,1122.9,2030,3624.2,3147.1,2605.6,4122,3680,3669,3129,2638,3785,3710,5020,3670,8030,9350,11310,10260,7830
Madhya Pradesh,-118,-229.3,-187.8,-176.3,-79.1,-70.4,-35,59,145.8,-98,200.7,43.8,-285.3,448.1,190.5,477.4,1447.8,469.3,2871.8,2932.3,1319.3,3167.8,1169,4476,-1717,-33,-3332,-5088,-4060,-5500,-6840,-9910,-7460,-5880,-6370,-5590
Maharashtra,-121,-147.4,-210.1,-70.8,212,316.7,0.6,-74,240.8,374,54.7,276.1,728.5,121.9,-277.3,609.1,1590.6,2579.9,3925.9,4268.8,7834,8188.6,9371,8310,10033,3842,-810,-14803,-5580,8010,590,2270,-4210,5080,13880,3760
Manipur,-41,-10,-20.3,-24.4,-37.6,-70.4,-50,-72,-65,-33,-88.5,-73.3,-82.2,-140.9,-83.7,-72.9,-100,-65.3,-108.1,287.1,86.3,161.2,87,44,-92,-404,-448,-1216,-1250,-860,-1350,-650,-1500,-1560,-970,-690
Meghalaya,-30,-8.1,-11.8,-24.6,-31.2,-48,-58,-66,-77.7,-50,-42.2,-35.6,-18.2,-17.9,-73.3,-103.5,-113.5,-11.6,-17.3,-15.9,-52.7,33.6,-84,-85,50,-72,-235,-188,-130,-260,-250,180,-540,-720,-1220,-780
Mizoram,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,1.5,-22,52,-43,-64,-157.1,-79,-47.2,-83.9,-74.9,-62.3,-46.9,-59.9,-44.1,-59.3,193.4,260.4,109,-83,-107,-66,-252,-131,-340,-260,30,-290,-30,150,950,-1080
Nagaland,-52,-7.8,-5.5,3.3,-37.6,-60.8,-34,-23,-41.2,46,5.2,-6.3,13,47.2,90.8,64.1,-8.8,10.9,13.4,36.3,0.4,-44.9,107,-547,-155,-207,-550,-424,-510,-470,-810,-710,-600,-750,-480,-230
Odisha,-81,-28,23,-0.4,74,60.1,20,75,107.8,105,19.6,187.7,135.7,274.4,459.6,807.1,830.5,904.5,2264.8,2573.9,1926.8,2829.6,1576,1421,522,-481,-2261,-4244,-3420,-1140,-3910,-5610,-5700,-3330,-3380,-5100
Punjab,-18,-62.6,-102.5,-59.3,9.4,-7.3,-90,229,244.1,221,544.2,480.9,635.6,766.9,741.8,450.2,1357.1,1483.9,2628.7,2727.4,2336,3781.2,3754,3563,3391,1242,1749,3823,3860,5250,5290,6810,7410,6540,6240,6390
Rajasthan,-65,-34.3,-54.5,-44.7,75.9,2.2,60,356,218.5,30,-168,-48.5,109.5,300.7,424.8,701.9,866,581.8,2996.3,3639.9,2633.6,3795.7,3934,3424,2143,660,-638,-1653,830,4750,-1050,-3360,-3450,1040,4220,-560
Sikkim,-7,-7.5,-12.8,-6.8,-18.7,-14.1,-32,-28,-36,-19,-31.4,-27.4,-29.5,-36,-19.8,-60,-38.7,-41.4,54.9,-1.9,-99.3,-142.9,-198,-160,-169,-197,-229,-351,-380,-520,-140,-440,-780,-870,-1280,-540
Tamil Nadu,-128,-81.7,-101.9,-51.7,-17.2,-188.6,-103,283,274.2,479,553.4,1903.9,1526.2,691.9,415.6,311.3,1103.6,1363.9,3436.6,4400.3,3435.8,2738.9,4851,1565,703,-1951,-2648,-4545,-1450,3530,2730,-1360,-1760,1790,3540,4620
Telangana,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0,-280,-530
Tripura,-36,-5.8,-15.2,-4.9,-36.5,-41.2,-42,-20,-15.1,-7,1.7,-15.6,-53.9,0.3,-35.6,-150.7,-121.8,-21.7,-92.7,22.6,96,-54.4,81,-106,-394,-633,-851,-904,-950,-1410,-810,-1670,-1840,-1700,-2360,-3400
Uttar Pradesh,-183,-353.4,-192.4,105.8,147.3,-174.6,177,-252,604.5,1031,1228.3,724.6,1014.5,1148.7,2002.7,2340.7,3179.1,4623.9,8696.2,7252.6,6289.3,6181.8,5117,18583,6993,1268,-4901,-3449,-1860,-7050,-3510,-6980,-5180,-10070,-32410,-34120
Uttarakhand,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,-10.6,99.6,457,761,950,74,-896,-637,-240,1170,10,-720,-1790,-1100,-2160,-40
West Bengal,23,87.8,242.4,206.2,371.9,-82.9,188,115,137.2,477,1018.9,646.1,436.6,984.3,767.1,1250.2,2135.2,2294.1,4856.2,9287.3,7581.3,8856.1,8635,9149,8228,7391,8333,8147,14710,21580,17270,14570,13820,18920,10360,0
Delhi,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,οΏ½,-59,-549.6,-419.4,-764.2,-1158.7,-820,-751.3,-1747.5,-1209.6,-2068,-2261,-2735,-4328,-4438,-5142,-4590,-6550,-10640,-4430,-4900,-5610,-6100,-8160
Puducherry,,,,,,,,,,,,,,,,,,,,,,,οΏ½,οΏ½,οΏ½,-7,43,65,110,240,340,450,-90,180,-90,0
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/Revenue_Deficits EDA app/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@


# stocks Visualization App

<img width="779" alt="Screenshot 2024-08-09 at 7 30 18β€―PM" src="https://github.com/user-attachments/assets/eac35eea-22c0-496e-b4e1-9b08ce705d7c">



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!