I have 4 CSV files that i need to process (filter out Part segment and then merge them) but the problem is that they do not fit in my memory. So I decided to: [open - filter - write out] each one of theses 4 files and merge them after reopening the filtered version.
I learned that it was good practice to decouple the functionality (filter functionality, merge functionality, write out functionality) but in this case splitting filter and dumping out functionality seem silly, it would be like wrapping an existing function from pandas library. But merging the 2 functionality make me also uncomfortable since I have heard that it is not good practice to write functions that return and have side effect (as writing out a CSV) as follow:
def exclude_segm_part(f):
""" Filter out "Part client" on credit selection and write it on disk
Args:
f (string): filepath of the credit base (csv)
"""
df = pd.read_csv(f,sep=';',encoding="latin")
df_filter = df[df.LIB_SEGM_SR_ET!="PARTICULIERS"]
filename = "{base}.txt".format(base=os.path.basename(f).split(".txt")[0])
df_filter.to_csv(filename,index=False,sep=';')
return df_filter
What would be your suggestion? (Hope my question is clear enough, I want to get the good practice of coding in data science environment)