Use the Chardet module to determine the encoding of the data, and the input parameter is the STR type.
#Coding:utf-8ImportCCHARDETF=open ('Hadoop.txt','R')#Open Text file, read-onlyAbout=f.read ()#reading text contentPrintCchardet.detect (about)#Determining string encoding
#converts the original encoding of a string to Unicode encoding and then to UTF-8 encodingPrintAbout.decode ('GBK'). Encode ('Utf-8')
Pd. Dataframe Data type Conversions
#-*-coding:utf-8-*-ImportPandas as Pddf= PD. DataFrame ([{'col1':'a','col2':'1'}, {'col1':'b','col2':'2'}])PrintDFPrint 'viewing DF Object data Types'Printdf.dtypesdf['col2'] = df['col2'].astype ('int')Print '-------------------------------------------'Printdf['col2']. dtypesdf['col2'] = df['col2'].astype ('float64')Print '-------------------------------------------'PrintDf.dtypes
Of course there are a lot of ways ...
Python encoding and type conversion