Background
I have some dataframes that I'm trying to split, then write the individual columns into binary files as signed shorts.
Code
for i in range(0, len(filesList)):
df = pd.read_csv(myPath + '/' + filesList[i], sep='\t', header=None)
dfA = df[1]
dfA = dfA - np.mean(dfA)
dfA = 10000*(dfA/(np.max(dfA)-np.min(dfA)))
dfA = dfA.astype(int)
dfA.to_csv(path=writeOutDirectoryPath + '/' + filesList[i] + 'LeadA', mode='wb', index=False)
Everything through making the series dfA into integers (which finishes their conversion into a format that will be readable as signed shorts, I think; all my values are between -6000 and 6000 for this particular post-transform data set.
The Problem
I expect dfA.to_csv to write to the file in binary, hence mode='wb'. I get an error:
f = open(path, mode, errors='replace')
ValueError: binary mode doesn't take an errors argument
I must be doing something wrong, but I don't know what. Maybe to_csv can't write binary files out, but I can't find anything in the documentation that would indicate that. Barring telling me what I'm doing wrong with this, what's the best way to convert information in a DataFrame into a form that can be done as binary?
Edit
Writing the file out the CSV is trivial (and I can do that already). If anyone has a method to convert a CSV to a binary file, I'm completely open to that as well.