Skip to content

Instantly share code, notes, and snippets.

@alfonsokim
Last active October 3, 2018 00:26
Show Gist options
  • Save alfonsokim/c1fda241b347be5cb7f94ea364223344 to your computer and use it in GitHub Desktop.
Save alfonsokim/c1fda241b347be5cb7f94ea364223344 to your computer and use it in GitHub Desktop.
import os
import pandas
import openpyxl
writer = pandas.ExcelWriter('ruta al excel de salida', engine='openpyxl')
current_row = 0
all_excel_dir = 'ruta al directorio de exceles'
for fidx, one_file in enumerate(os.listdir(all_excel_dir)):
if one_file.split('.')[-1] == 'xlsx':
path = os.path.join(all_excel_dir, one_file)
df = pandas.read_excel(path, index=False)
dft = pandas.DataFrame(df.T, columns=df.index.values)
dft.to_excel(writer, startrow=current_row, index=False, header=fidx == 0)
current_row += dft.shape[0] + (1 if fidx == 0 else 0)
writer.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment