python pie
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
data=pd.read_csv(
'C:\\Users\\XXX\\Desktop\\pfizer0506\\fastQC.Batch14.45_6MAY2020.xls',
engine='python',
sep='\t'
)
data.rename(
columns={"rRNA_rate%":"rRNA"}, #更改列名
inplace=True
)
bins=[0,10,20,30,50,100]
labels=["<10%","10~20%","20~30%","30~50%","50~100%"]
data['rRNA_rate']=pd.cut(
data.rRNA,
bins, # 按照区间进行分组
right=False,
labels=labels,
)
print(data)
grouped=data.groupby('rRNA_rate') # 按照 rRNA_rate 列进行分组
a=data['rRNA_rate'].value_counts(normalize=True) # 计算分组数目
b = list(filter(lambda x : x!=0,a.values)) # 去除统计值为0的列
labes=["rRNA<10%","rRNA 10-20%"]
plt.pie(b,labels=labes,autopct='%1.2f%%') # 绘制饼图