写在前面
- 积累工作中常用,但费时的数据处理技巧。
- 利用碎片化时间完成小记。
P1: Pandas Series非科学计数法显示
pd.set_option('display.float_format', lambda x : '%.5f' % x)
data_test.sample(3)
P2: plt.title/labels 引用中文
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
plt.figure(figsize=(6,6))
labels = '一般风险群', '低风险群', '极高风险群', '次高风险群','高风险群'
randoms = [23,7,13,51,9]
explode = [0, 0, 0.05, 0,0.1]
patches,texts,autotexts=plt.pie(x=randoms, labels=labels, explode=explode,autopct='%3.1f %%', labeldistance=1.1, startangle = 90,pctdistance = 0.6)
plt.title(u"企业破产风险占比",y = 1.1,fontsize = 12)
plt.show()
P3: Pandas 数据堆叠化显示
import matplotlib.pyplot as plt
plt.figure(figsize=(12,4))
plt.title("Series数据堆叠化显示示例",FontProperties=font,fontsize = 18)
plt.bar(stacked_df.index.tolist(),stacked_df.sort_index(ascending=True,axis=0).apple.tolist())
plt.bar(stacked_df.index.tolist(),stacked_df.sort_index(ascending=True,axis=0).apple.tolist(),bottom=stacked_df.sort_index(ascending=True,axis=0).apple.tolist())
plt.grid()
plt.xlabel('下标',FontProperties=font,fontsize = 12)
plt.ylabel('数据量',FontProperties=font,fontsize = 12)
plt.show()
最后