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()

 

posted @ 2023-03-27 10:34  myrj  阅读(349)  评论(0编辑  收藏  举报