I'm trying to read and process in parallel a list of csv files and concatenate the output in a single pandas dataframe
for further processing.
My workflow consist of 3 steps:
create a series of pandas dataframe by reading a list of csv files (all with the same structure)
def loadcsv(filename): df = pd.read_csv(filename) return df
for each dataframe create a new column by processing 2 existing columns
def makegeom(a,b): return 'Point(%s %s)' % (a,b)
def applygeom(df): df['Geom']= df.apply(lambda row: makegeom(row['Easting'], row['Northing']), axis=1) return df
concatenate all the dataframes in a single dataframe
frames = [] for i in csvtest: df = applygeom(loadcsv(i)) frames.append(df) mergedresult1 = pd.concat(frames)
In my workflow I use pandas (each csv (15) file has more than >> 2*10^6 data points) so it takes a while to complete. I think this kind of workflow should take advantage of some parallel processing (at least for the read_csv
and apply
steps) so I gave a try to dask, but I was not able to use it properly. In my attempt I did'n gain any improvement in speed.
I made a simple notebook so to replicate what I'm doing:
https://gist.github.com/epifanio/72a48ca970a4291b293851ad29eadb50
My question is ... what's the proper way to use dask to accomplish my use case?