Skip to content

Instantly share code, notes, and snippets.

@mhweber
Created September 10, 2020 00:54
Show Gist options
  • Select an option

  • Save mhweber/d298063929c2dbe63b509efc62f55bd2 to your computer and use it in GitHub Desktop.

Select an option

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
# -*- 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)
@Alejogb1

Alejogb1 commented Sep 6, 2023

Copy link
Copy Markdown

thank you man

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment