我有以下2D Numpy数组:
insert_statements = [[ 'INSERT OR IGNORE INTO mytable VALUES (\'Tue Nov 05 00:00:04 +0000 2013\', \'397513609711874048\', \'JUST GOT HOME AND SAW WE BROKE THE VEVO RECORD! IF YOU HELPED I LOVE YOU\', \'<a href="twitter /download/iphone" rel="nofollow">Twitter for iPhone</a>\', NULL, NULL, NULL, 0, NULL);'],
[ 'INSERT OR IGNORE INTO mytable VALUES (\'Tue Nov 05 00:00:04 +0000 2013\', \'397513609732845568\', \'We are here to play tough cricket: Richardson to/ma8h\', \'<a href="http://scoop.so" rel="nofollow">SCOOP Hot News India</a>\', NULL, NULL, NULL, 0, NULL);'],
[ 'INSERT OR IGNORE INTO mytable VALUES (\'Tue Nov 05 00:00:04 +0000 2013\', \'397513609728651265\', \'RT @ertiaraa: RT @MeilindaMP: somebody that i used to know\', \'<a href="twitter /download/android" rel="nofollow">Twitter for Android</a>\', NULL, NULL, NULL, 0, NULL);']]
它有dtype('<U283')
。我认为这与字节编码方式有关?我不知道如何将其改为Python中的标准。
当我尝试使用numpy.savetxt
导出它时,收到一条错误消息:
TypeError: Mismatch between array dtype ('<U283') and format specifier ('%10.5f')
这是导出代码:
np.savetxt('C:\\Users\\Output.csv', insert_statements, delimiter=',')
我已经看到Stack Overflow上有几个相关的问题,但没有一个解决方案在我的案例中有所帮助。我试过了:
insert_statements2 = insert_statements.astype('object')
但这会产生错误:
TypeError: Mismatch between array dtype ('object') and format specifier ('%10.5f')
我也尝试过:
insert_statements2 = insert_statements.astype('%10.5f')
给出错误:
TypeError: data type "%10.5f" not understood
我还尝试在fmt
函数中设置numpy.savetxt
参数,但仍然失败并且给出了关于数组dtype和格式说明符之间不匹配的相同错误。
非常感谢任何帮助!