Last active
August 20, 2023 01:29
-
-
Save rchardptrsn/1e54a6b254c5a589f071c991f49e2c0b to your computer and use it in GitHub Desktop.
combine files.py
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
import glob as glob | |
import pandas as pd | |
#define path to CSV files | |
path = r'ndvi data/*.csv' | |
#identify all CSV files | |
all_files = glob.glob(path) | |
#merge all CSV files into one DataFrame | |
fireNDVI = pd.concat((pd.read_csv(f) for f in all_files), ignore_index=True) | |
############################## | |
# Get a list of missing values | |
missing_values = list(set(gdf['OBJECTID'].unique().tolist()) - set(fireNDVI['OBJECTID'].unique().tolist())) | |
# Subset gdf to isolate the missing values | |
missing_rows = gdf[gdf['OBJECTID'].isin(missing_values)] | |
print(f"There are {gdf['OBJECTID'].nunique() - fireNDVI['OBJECTID'].nunique()} missing OBJECTIDs") | |
print(f"These missing values are {missing_values}") | |
############################## | |
# Download the NDVI for the missing records | |
# Collect all | |
collectAllNDVI(missing_rows) | |
print('Complete.') | |
############################## | |
# Re-combine the data files include any missing files | |
# identify all CSV files in the path | |
all_files = glob.glob(path) | |
#merge all CSV files into one DataFrame | |
fireNDVI = pd.concat((pd.read_csv(f) for f in all_files), ignore_index=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment