Reputation: 557
Here's what my data looks like,
user_id article_id send_time author_id topic_id type_id
0 11460 66 2015-01-02 18587 72 22
1 5475 66 2015-01-02 18587 72 22
2 1205 66 2015-01-02 18587 72 22
3 17040 66 2015-01-02 18587 72 22
4 18940 66 2015-01-02 18587 72 22
I tried using this code, once with format option once without. Without that option I get an error
Code
np.savetxt(r'C:/Users/AmitSingh/Desktop/Data/data_scientist_test/access_log/new_dataframe.txt',new_dataframe.values)
Error
TypeError: Mismatch between array dtype ('object') and format specifier ('%.18e %.18e %.18e %.18e %.18e %.18e')
With the format option
Code
np.savetxt(r'C:/Users/AmitSingh/Desktop/Data/data_scientist_test/access_log/new_dataframe.txt',new_dataframe.values,fmt='%d')
Error
TypeError: Mismatch between array dtype ('object') and format specifier ('%d %d %d %d %d %d')
What else can I do? I need to write this in a txt file, since there are too many rows to write in a csv/excel file
Upvotes: 0
Views: 270
Reputation: 7185
You are getting that error because of mixed types (including object
references) in your DataFrame.
Easiest solution is to use pandas.DataFrame.to_csv method instead of numpy.savetxt
:
new_dataframe.to_csv(r'C:/Users/AmitSingh/Desktop/Data/data_scientist_test/access_log/new_dataframe.txt')
Upvotes: 1