0

I have being trying to export a table to a csv file. The table is copied to the clipboard and it is ready to be put into a csv (at least manually).

I have seen that you can read with pandas anything that you have in the clipboard and assign it to a dataframe, so I tried this code.

df = pd.read_clipboard()
df
df.to_csv('data.csv')

However, I got this error:

pandas.errors.ParserError: Expected 10 fields in line 5, saw 16. Error could possibly be due to 
quotes being ignored when a multi-char delimiter is used.

I have being looking for a solution or an alternative but failed.

Thanks in advance!

  • 1
    Is the pandas module a requrment here ? You could read clipboard like described here: https://stackoverflow.com/questions/101128/how-do-i-read-text-from-the-clipboard (at least on Windows) and write it with standard csv module or one of available modules for xlsx (eg. xlsxwriter) – poleszcz Sep 22 '21 at 11:06
  • It would be highly recommended. The thing is that when I store the data in the clipboard, if I paste it manually into the xlsx file it works amazingly well (even keeps the formats). However it is never that easy... :( I have thought to move the data to a txt file but it would need a lot of parsing so I'm aiming for this approach –  Sep 22 '21 at 11:20
  • Does this error occur all the time or just when you have specific things on your clipboard? – Kazi Sep 22 '21 at 12:46
  • And what is the source of data. I bet it would be better to retrieve data automatically from its origin instead of clipboard. – poleszcz Sep 22 '21 at 13:04

0 Answers0