This project fetches and analyzes FEMA NFIP Claims data based on a given ZIP code, utilizing Langchain and Google Generative AI to process and interact with the data.
- Fetch FEMA NFIP Claims data using FEMA API.
- Analyze and display data in a tabular format.
- Perform calculations and generate insights using Langchain tools.
You will need to use your own API key, from (https://makersuite.google.com/)
-
Clone the repository:
git clone https://github.com/yourusername/fema-data-analysis.git cd fema-data-analysis
-
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install the required packages:
pip install -r requirements.txt
-
Create a
.env
file in the project root and add your Google API key:GOOGLE_API_KEY=your_google_api_key_here
-
Add
.env
to your.gitignore
to ensure it is not pushed to GitHub:.env
-
Run the script:
python script.py
-
Enter your ZIP code when prompted.
-
The script will fetch and display the FEMA data, and export it to a CSV file named
fema_data_<zip_code>.csv
.
To run this project on Google Colab, follow these steps:
-
Open Google Colab in your browser: Google Colab.
-
Create a new notebook.
-
Upload the
script.py
file to the Colab notebook by clicking on the folder icon on the left sidebar and then the upload button. -
Install the required packages by running the following cell:
!pip install requests pandas ipython langchain langchain-google-genai python-dotenv
-
Upload your
.env
file to the Colab notebook. -
Add the following code cell to load the environment variables:
from dotenv import load_dotenv import os load_dotenv() os.environ["GOOGLE_API_KEY"] = os.getenv("GOOGLE_API_KEY")
-
Add a code cell to run the script:
!python script.py
-
Run the cells in the notebook to execute the script.
The project includes several functions to analyze the FEMA data:
- Total Building Damage Amount: Calculates the total building damage amount.
- Average Contents Damage Amount: Calculates the average contents damage amount.
- Most Recent Date of Loss: Finds the most recent loss date.
- Count Policies by Flood Zone: Counts policies by flood zone.
- Total Number of Claims: Calculates the total number of claims.
- Total Building and Contents Damage Amount: Calculates the total sum of building and contents damage amounts.
This project is licensed under the MIT License.
Contributions are welcome! Please open an issue or submit a pull request for any changes.
For any inquiries, please contact Ryan.