Combine excel files with the same format into one – Python code example

import pandas as pd
import numpy as np
import dateutil

import glob
file_names=glob.glob(“/Users/XXXX/Downloads/XXXX/u*.xlsx”)

combining excel .xlsx files starting with u together

all_data = pd.DataFrame()
for f in glob.glob(“/Users/XXXXX/Downloads/XXXXX/u*.xlsx”):
df = pd.read_excel(f)
all_data = all_data.append(df,ignore_index=True)

all_data.shape

write it to excel

writer = pd.ExcelWriter(‘/Users/XXX/Downloads/file/combined_samples.xlsx’)
all_data.to_excel(writer)

extracting column

a=all_data[[“a”]]

counting unique value in a column

all_data[[“a”]].nunique()

taking unique value in a column

unique_a_list=all_data.a.unique()

write to data frame

df = pd.DataFrame(data=unique_a_list)

write it to excel

writer = pd.ExcelWriter(‘/Users/XXXX/Downloads/files/results.xlsx’)
df.to_excel(writer)

Be the first to comment

Leave a Reply

Your email address will not be published.


*