我在下面有df,我想创建3个散点图(天与A,天与B,天与C),显示所有数据点以及一条通过每天平均值的线。
例如,plt.plot(df.iloc[:,0],df.iloc[:,3], 'b')
给了我一条穿过每个点的线(第3个图),但是我想要一条通过平均值的线。
这是我的代码:
data=np.array([[1,4.4,40.1,55],
[1,4.5,40.6,45.6],
[1,4.4,41.5,61.3],
[4,10,26,79.4],
[4,11.2,25.3,80.9],
[4,10.5,23.6,84],
[10,5.6,12.7,58.2],
[10,6,10.9,60.8],
[10,7.3,8.7,70.5,],
[15,2.5,5.4,98.7],
[15,2.7,6.2,95.3],
[15,2.8,4.7,88.9],
[25,0.8,3.3,25.4],
[25,0.5,1,28.6],
[25,1,5,23.6]])
df = pd.DataFrame(data[:,0:],columns=['days','A','B','C'])
plt.subplot(3, 1, 1)
plt.plot(df.iloc[:,0],df.iloc[:,1], 'ro')
plt.subplot(3, 1, 2)
plt.plot(df.iloc[:,0],df.iloc[:,2], 'ro')
plt.subplot(3, 1, 3)
plt.plot(df.iloc[:,0],df.iloc[:,3], 'ro')
plt.plot(df.iloc[:,0],df.iloc[:,3], 'b')
参考方案
您可以使用groupby
将值分组,然后绘制平均值。根据this答案改编和查找均值的方法。其余部分是密谋部分。
df = pd.DataFrame(data[:,0:],columns=['days','A','B','C'])
df_mean = df.groupby('days')['A','B','C'].mean()
plt.subplot(3, 1, 1)
plt.plot(df.iloc[:,0],df.iloc[:,1], 'ro')
plt.plot(df_mean.index, df_mean['A'], '-r')
plt.subplot(3, 1, 2)
plt.plot(df.iloc[:,0],df.iloc[:,2], 'ro')
plt.plot(df_mean.index, df_mean['B'], '-r')
plt.subplot(3, 1, 3)
plt.plot(df.iloc[:,0],df.iloc[:,3], 'ro')
plt.plot(df_mean.index, df_mean['C'], '-r')
在返回'Response'(Python)中传递多个参数 - python我在Angular工作,正在使用Http请求和响应。是否可以在“响应”中发送多个参数。角度文件:this.http.get("api/agent/applicationaware").subscribe((data:any)... python文件:def get(request): ... return Response(seriali…
Python exchangelib在子文件夹中读取邮件 - python我想从Outlook邮箱的子文件夹中读取邮件。Inbox ├──myfolder 我可以使用account.inbox.all()阅读收件箱,但我想阅读myfolder中的邮件我尝试了此页面folder部分中的内容,但无法正确完成https://pypi.python.org/pypi/exchangelib/ 参考方案 您需要首先掌握Folder的myfo…
R'relaimpo'软件包的Python端口 - python我需要计算Lindeman-Merenda-Gold(LMG)分数,以进行回归分析。我发现R语言的relaimpo包下有该文件。不幸的是,我对R没有任何经验。我检查了互联网,但找不到。这个程序包有python端口吗?如果不存在,是否可以通过python使用该包? python参考方案 最近,我遇到了pingouin库。
我不明白为什么sum(df ['series'])!= df ['series']。sum() - python我正在汇总一系列值,但是根据我的操作方式,我会得到不同的结果。我尝试过的两种方法是:sum(df['series']) df['series'].sum() 他们为什么会返回不同的值?示例代码。s = pd.Series([ 0.428229 , -0.948957 , -0.110125 , 0.791305 , 0…
Python ThreadPoolExecutor抑制异常 - pythonfrom concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED def div_zero(x): print('In div_zero') return x / 0 with ThreadPoolExecutor(max_workers=4) as execut…