【发布时间】:2018-10-14 13:35:28
【问题描述】:
我正在尝试创建一个如下所示的 pandas 数据框:
-5 0 5
index
-5 NaN slope slope
0 slope NaN slope
5 slope slope NaN
但我能得到的最接近的是下面的代码,它返回一个只有一列的数据帧(这是通过 ctr1 循环的最后一次迭代的列表)
weather = np.linspace(-5, 5, 3)
for ctr1 in weather:
slope_list = []
X1 = round(ctr1,1)
for ctr2 in weather:
X2 = round(ctr2,1)
Y1 = regressor[0] * X1**3 + \
regressor[1] * X1**2 + \
regressor[2] * X1 + \
regressor[3]
Y2 = regressor[0] * X2**3 + \
regressor[1] * X2**2 + \
regressor[2] * X2 + \
regressor[3]
slope = (Y2-Y1)/(X2-X1)
slope_list.append(slope)
df_final = pd.DataFrame({X1:slope_list})
谁能帮忙?
【问题讨论】:
-
请提供预期的输出。
-
嗨,andrew_reece,预期的输出就像我在顶部显示的那样,每个“斜率”都是一个数字(基于使用 X1、X2、Y1、Y2 的计算)。