我在DataFrame中有以下数据:
+----------------------+--------------+-------------------+
| Physician Profile Id | Program Year | Value Of Interest |
+----------------------+--------------+-------------------+
| 1004777 | 2013 | 83434288.00 |
| 1004777 | 2014 | 89237990.00 |
| 1004777 | 2015 | 96321258.00 |
| 1004777 | 2016 | 186993309.00 |
| 1004777 | 2017 | 205274459.00 |
| 1315076 | 2013 | 127454475.84 |
| 1315076 | 2014 | 156388338.20 |
| 1315076 | 2015 | 199733425.11 |
| 1315076 | 2016 | 242766959.37 |
+----------------------+--------------+-------------------+
我想绘制一个趋势图,其中x轴为“计划年度”,y轴为“兴趣值”,并且每个医师个人资料ID的行都不同。完成这项工作的最佳方法是什么?
答案 0 :(得分:1)
我会考虑的两条路线:
pip install matplotlib
import matplotlib.pyplot as plt
和this cheatsheet 希望对您有所帮助!
答案 1 :(得分:1)
我尝试了一些事情并能够实现它:
years = df["Program_Year"].unique()
PhysicianIds = sorted(df["Physician_Profile_ID"].unique())
pd.options.mode.chained_assignment = None
for ID in PhysicianIds:
df_filter = df[df["Physician_Profile_ID"] == ID]
for year in years:
found = False
for index, row in df_filter.iterrows():
if row["Program_Year"] == year:
found = True
break
else:
found = False
if not found:
df_filter.loc[index+1] = [ID, year, 0]
VoI = list(df_filter["Value_of_Interest"])
sns.lineplot(x=years, y=VoI, label=ID, linestyle='-')
plt.ylabel("Value of Interest (in 100,000,000)")
plt.xlabel("Year")
plt.title("Top 10 Physicians")
plt.legend(title="Physician Profile ID")
plt.show()