我在pandas中有一个数据框,其中包含我想要分组的信息.从每个组中,我想从该组中的整个列中减去某列的第一个值.然后应将这些值作为附加列添加到数据框中.我的初始数据框的一个示例:
time sample x y mass
3 1.0 216 12 12
4 1.0 218 13 12
5 1.0 217 12 12
6 1.0 234 13 13
1 2.0 361 289 23
2 2.0 362 287 22
3 2.0 362 286 22
5 3.0 124 56 18
6 3.0 126 52 17
Run Code Online (Sandbox Code Playgroud)
结果我想要的是:
sample time x y mass xdiff
1.0 3 216 12 12 0
1.0 4 218 13 12 2
1.0 5 217 12 12 1
1.0 6 214 13 …Run Code Online (Sandbox Code Playgroud) 我决定试一试seaborn 0.11.0 版!据我所知,使用将替换 distplot 的 displot 函数。我只是想弄清楚如何将高斯拟合绘制到直方图上。这是一些示例代码。
import seaborn as sns
import numpy as np
x = np.random.normal(size=500) * 0.1
Run Code Online (Sandbox Code Playgroud)
使用 distplot 我可以做到:
sns.distplot(x, kde=False, fit=norm)
Run Code Online (Sandbox Code Playgroud)
但是如何在 displot 或 histplot 中进行呢?
随着时间的推移,我有一组对象及其位置。我想获得每辆车与其最近邻居之间的距离,并计算每个时间点的平均值。示例数据框如下:
time = [0, 0, 0, 1, 1, 2, 2]
x = [216, 218, 217, 280, 290, 130, 132]
y = [13, 12, 12, 110, 109, 3, 56]
car = [1, 2, 3, 1, 3, 4, 5]
df = pd.DataFrame({'time': time, 'x': x, 'y': y, 'car': car})
df
x y car
time
0 216 13 1
0 218 12 2
0 217 12 3
1 280 110 1
1 290 109 3
2 130 3 4
2 132 56 5 …Run Code Online (Sandbox Code Playgroud)