2017-03-27 1 views
3

다음과 같이 팬더 데이터 프레임이 있습니다. Python-table (ax, df)에서 한자 글꼴을 설정하는 방법

enter image description here

comment_corr=comment_book_content[['price','sale_num','sale_revenue','time_count','uid_num','vouch_count','comment_num']] 
comment_corr.columns=[u'价格',u'销售数量',u'销售收入',u'总阅读时间',u'净用户数',u'兑换数',u'评论数',] 
comment_corr_df=comment_corr.corr(method='pearson') 
comment_corr_df=comment_corr_df.reset_index() 
comment_corr_df 

지금, 나는 내 remport에 넣을 수 있도록 그림으로이 dataframe을 저장할. 나는 다음과 같은 방법을 시도했다.

fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(6, 3)) 
ax.set_frame_on(False) 
ax.xaxis.set_visible(False) # hide the x axis 
ax.yaxis.set_visible(False) # hide the y axis 
ax.set_title(u'书评图书各指标相关性分析',fontproperties=font,fontsize=15) 

plt.subplots_adjust(left=0.2, bottom=0.2, right=0.8, top=0.4,hspace=0.1, wspace=0.3) 
plt.tight_layout() 

tabla=table(ax, comment_corr_df, rowLabels= ['']*comment_corr_df.shape[0],colWidths= [0.17]*len(comment_corr_df.columns),loc='center') # where df is your data frame 
tabla.auto_set_font_size(False) # Activate set fontsize manually 
tabla.set_fontsize(10) # if fontsize is necessary ++colWidths 
tabla.scale(1.6,1.8) # change size table 

그러나,이 방법 table 수없는 성공적 본 한자는 아래와 같이 한자 열 이름 및 행 인덱스 등. enter image description here

내 질문은 일반적으로 dataframe에 중국 문자를 표시 할 수 있도록 table method,에서 글꼴을 설정하는 방법입니다

답변

0

당신이해야 코드의 시작 부분에 인코딩 절 :

# -*- coding: utf-8 -*- 

이것은 코드의 첫 번째 줄이어야합니다.

+0

답장을 보내 주셔서 감사합니다. 이 방법을 시도했지만 작동하지 않습니다. –

관련 문제