+ 1
Importing and appending records from multiple files in Python
I have a list of identically formatted CSV files in a file directory. I want to import each of these and extract the information from each as a data frame. They each have a number of variable names and one row of values. Then, I want to append each of these individual imports into one large data frame. Have attempted for loops with little success. Any suggestions how to achieve this in a neat 'Pythonic' fashion?
1 Respuesta
+ 2
import os
import glob
import pandas as pd
import numpy as np
path = "my_dir_full_path"
allfiles = glob.glob(os.path.join(path,"*.csv"))
np_array_list = []
for file_ in allFiles:
df = pd.read_csv(file_,index_col=None, header=0)
np_array_list.append(df.as_matrix())
comb_np_array = np.vstack(np_array_list)
big_frame = pd.DataFrame(comb_np_array)
big_frame.columns = ["col1","col2"....]