python - Change Pandas index datatype on MultiIndex -
i have pandas dataframe 2 indexes
column1 indexa indexb 1001 aaa 1 bbb 1 ccc 1 ddd 1
created by
pd.read_sql(sql=sql, index_col=['indexa', 'indexb'])
mysql reading in indexb
unicode , convert string. goal pivot table , have entries in indexb
column names. when unicode values following column names:
� � � � � � � � �
when running
pd.read_sql(sql=sql, index_col=['indexa', 'indexb']).unstack().fillna(0)
edit: comment suggested following:
df = pd.read_sql(sql) df['indexb'] = df['indexb'].astype(str) df = df.set_index(('indexa', 'indexb'), drop=true)
which nice work around problem (thank you). still nice know if can done during initialization.
Comments
Post a Comment