python pandas保存 。dta文件报错:UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-2: ordinal not in range(256)应对
pandas 保存.dta文件时报错:
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-2: ordinal not in range(256)
import pandas as pd df = pd.read_sql('SELECT * FROM kehu1', con=connect) df.to_stata('kehu1.dta') connect.close()
解决方法:
import pandas as pd df = pd.read_sql('SELECT * FROM kehu1', con=connect) df.to_stata('kehu1.dta',version=119) connect.close()