Created
September 10, 2020 00:54
-
-
Save mhweber/d298063929c2dbe63b509efc62f55bd2 to your computer and use it in GitHub Desktop.
Combine multiple .csv files into one pandas dataframe and write out to a zip file
This file contains 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
# -*- coding: utf-8 -*- | |
""" | |
Created on Wed Sep 9 16:46:15 2020 | |
@author: mweber | |
""" | |
# Combine hydro-region tables if desired | |
import pandas as pd | |
import glob | |
path = r'L:/Priv/CORFiles/Geospatial_Library_Projects/StreamCat/FTP_Staging/StreamCat/HydroRegions' # use your path | |
all_files = glob.glob(path + "/AgriculturalNitrogen*.csv") | |
full_files = [] | |
for filename in all_files: | |
df = pd.read_csv(filename, index_col=None, header=0) | |
full_files.append(df) | |
frame = pd.concat(full_files, axis=0, ignore_index=True) | |
compression_opts = dict(method='zip', | |
archive_name='out.csv') | |
frame.to_csv('c:/users/mweber/temp/AgNit.zip', compression=compression_opts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you man