Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

save to text from pandas dataframe

Tags:

python

pandas

Im trying to save my dataframe which consists of 2 colums into a text file,I get this error of mismatch between array dtype,any suggestions on what i could do?

The error Image

like image 844
Ryan Avatar asked Mar 08 '23 11:03

Ryan


1 Answers

Use DataFrame.to_csv:

df.to_csv('hopefully.txt', index=False, sep=' ', header=None)

For the file to be saved without a comma, use the sep=' '. To cut off the column title, header=None.

like image 171
jezrael Avatar answered Mar 21 '23 04:03

jezrael