-2

I have created a set of CSVs using Pandas to_csv() method. I am on Windows.

The CSVs are then fed into POST requests that insert the data into a CMS.

However, 2 out of the 15 columns in the CSV are showing up blank after POST request.

My colleague confirms the columns are also blank on her Mac machine.

I've tried optional arguments like encoding='utf-8' and line_terminator='\n'.

Related problem: I suspect some optional parameter on to_csv() would do the trick but testing is tricky since I can't replicate the problem locally... I've Ubuntu + Docker and Ubuntu + VirtualBox but as far as I can see the data is showing up OK.

There are a few SO posts similar - but I can't find a good answer for going From_Windows_to_Mac/Linux

# df[df['foo']=='bar'].to_csv('testing-1.csv', encoding='utf-8')
# df[df['foo']=='bar'].to_csv('testing-2.csv', encoding='utf-8', line_terminator='\n')


# df[df['foo']=='bar'].to_csv('testing-3.csv', index=False, encoding='ascii')

df[df['foo']=='bar'].to_csv('testing-4.csv', index=False, encoding='ascii', header=False)
mustacheMcGee
  • 481
  • 6
  • 19
  • Open the files up in notepad before sending the CSVs via post. Are the 2 columns there or not? – A H Dec 31 '20 at 21:28
  • They are there on my Windows machine. Apparently, they're not there when opened on a Mac. – mustacheMcGee Dec 31 '20 at 22:20
  • Try creating a csv manually (i.e. 3 rows) in notepad. Does the problem exist? If so, then it seems the issue is with the POST doing some processing of the data. – A H Dec 31 '20 at 22:25
  • I like that idea. I'm trying ```quoting=csv.QUOTE_NONNUMERIC``` also. Will see if that works – mustacheMcGee Dec 31 '20 at 23:21

1 Answers1

0

The issue was quotations in CSV b/w Windows and Mac/Linux. Fixed this by adding quoting=csv.QUOTE_NONNUMERIC

import csv
df.to_csv('test.csv', encoding='utf-8', line_terminator='\n', quoting=csv.QUOTE_NONNUMERIC)
mustacheMcGee
  • 481
  • 6
  • 19