我尝试将numpy.ndarray
写入文件。
我用
unique1 = np.unique(df['search_term'])
unique1 = unique1.tolist()
下次再试试 (一)
edf = pd.DataFrame()
edf['term'] = unique1
writer = pd.ExcelWriter(r'term.xlsx', engine='xlsxwriter')
edf.to_excel(writer)
writer.close()
和2)
thefile = codecs.open('domain.txt', 'w', encoding='utf-8')
for item in unique:
thefile.write("%s\n" % item)
但都返回UnicodeDecodeError: 'utf8' codec can't decode byte 0xd7 in position 9: invalid continuation byte
如果将字符串编码为utf8,则第二个示例应该可以使用。你知道吗
以下在Python2中使用utf8编码的文件:
输出:
相关问题 更多 >
编程相关推荐