python dataframe written to the txt document, and write Chinese garbage problem

PANDAS
PANDAS NumPy is a tool, the tool to solve data analysis tasks created based on. Pandas included a large library and some standard data model provides the tools needed to efficiently operate large data sets. pandas provides a number of functions and methods enable us to quickly and easily handle the data.
DataFrame
DataFrame data structure is processed Pandas database table can be viewed as similar to the operation of the database python, Python is the most commonly used data mining tools


Txt written to, the direct use can be achieved to_csv

import pandas as pd
data = {'dog':[A,B,C,D,E],'cat':[a,b,c,d,e]}
df = pd.DataFrame(data)
df.to_csv('E:\\result.csv',index=False,sep=' ')

Added:
write to csv file: df.to_csv('E:\\result.csv')
... to json file: df.to_json('E:\\result.csv')
... to the html file: df.to_html('E:\\result.csv')
... to the clipboard: df.to_clipboard('E:\\result.csv')
... to the database:df.to_sql('E:\\result.csv')

If the written content with Chinese garbled problems result.txt after written:

df.to_csv('result.txt',index=False,sep=' ',encoding='utf_8_sig')

by ~ VII fish boat captain

Released eight original articles · won praise 3 · Views 652

Guess you like

Origin blog.csdn.net/lehek/article/details/94437151