I am trying to export a dataframe to a csv file so I can upload in into SAS later, however one of lines gets truncated even though it does not reach the csv cell limit of 32k characters. The code below demonstrates the problem
import pandas as pd
import numpy as np
bin1 = np.array(['finance'])
bin2 = np.array(['other', 'metallurgy', 'car trade/manuf', 'real_estate', 'transport', 'construction'])
bin3 = np.array(['trade whl', 'trade ret', 'tourism', 'food'])
data = {'var':'emp_sector','bin':[bin1,bin2,bin3]}
df = pd.DataFrame(data)
print(df)
var bin
0 emp_sector [finance]
1 emp_sector [other, metallurgy, car trade/manuf, real_esta...
2 emp_sector [trade whl, trade ret, tourism, food]
path = 'Y:/path/test.csv'
df.to_csv(path, encoding='ANSI')
After exporting the df I open the csv file and see this:
,var,bin
0,emp_sector,['finance']
1,emp_sector,"['other' 'metallurgy' 'car trade/manuf' 'real_estate' 'transport'
'construction']"
2,emp_sector,['trade whl' 'trade ret' 'tourism' 'food']
For some reason 'construction' is moved to the next line. Exporting to .txt gives the same results.
Can anyone help please?