我正在尝试使用滚动和应用功能来打印窗口
但我收到错误说
File "pandas/_libs/window.pyx", line 1649, in pandas._libs.window.roll_generic
TypeError: must be real number, not NoneType
Run Code Online (Sandbox Code Playgroud)
我的代码如下
def print_window(window):
print(window)
print('==================')
def example():
df = pd.read_csv('window_example.csv')
df.rolling(5).apply(print_window)
Run Code Online (Sandbox Code Playgroud)
我的数据就像
number sum mean
1 1 1
2 3 1.5
3 6 2
4 10 2.5
5 15 3
6 20 4
Run Code Online (Sandbox Code Playgroud)
我应该如何解决这个错误?我没有找到有关此错误的类似问题
谢谢 !
我正在尝试使用注释来显示条形图之间的差异。具体来说,显示所有条形与第一个条形之间的差异。
我的代码如下所示:
import plotly.graph_objects as go
lables = ['a','b','c']
values = [30,20,10]
difference = [ str(values[0] - x) for x in values[1:] ]
fig = go.Figure( data= go.Bar(x=lables,y=values,width = [0.5,0.5,0.5] ) )
fig.add_annotation( x=lables[0],y= values[0],
xref="x",yref="y",
showarrow=True,arrowhead=7,
ax = 1200, ay= 0 )
fig.add_annotation( x = lables[1], y=values[0],
xref="x",yref="y",
showarrow=True,arrowhead=1,
ax = 0 , ay = 100,
text= difference[0]
)
fig.show()
Run Code Online (Sandbox Code Playgroud)
结果图如下所示:

正如你所看到的,我试图用注释,以表明之间的差异a和b。但我不知道如何获得 .froma和顶部的水平线之间的垂直距离b。
我试图让一个箭头指向水平线的顶部b和c水平线。我想知道有没有办法获得这个垂直距离,或者有没有其他方法可以达到同样的结果?
我正在尝试使用时间戳作为窗口来处理我的数据。
我的数据就像
Timestamp A
8:17:11 AM 1
8:17:11 AM 2
8:17:12 AM 3
8:17:12 AM 4
8:17:13 AM 5
8:17:13 AM 6
Run Code Online (Sandbox Code Playgroud)
我的代码
df['test'] = df['A'].rolling('2s').sum()
Run Code Online (Sandbox Code Playgroud)
这里窗口大小为2秒,前两秒之前的输出数据应该为空
但我的结果就像
Timestamp A test
8:17:11 AM 1 1
8:17:11 AM 2 3
8:17:12 AM 3 6
8:17:12 AM 4 10
8:17:13 AM 5 12
8:17:13 AM 6 18
Run Code Online (Sandbox Code Playgroud)
其中显示 8:17:11 的结果
当数据大小小于窗口大小时,是否有办法禁用结果显示的功能?
我尝试使用 min_period,文档中说
窗口中需要有值的最小观测数(否则结果为 NA)。
但它似乎不适用于时间窗口
我该如何解答这个问题呢?
我正在尝试使用 plotly 绘制一个简单的图形
我的代码如下所示
import plotly.express as px
x = [1,2,3]
y = [1,2,3]
fig = px.line(x=x, y=y,labels={'x':x_name,'y':y_name})
fig.show()
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时,有时浏览器会显示 This site can’t be reached
当浏览器显示时我应该如何解决这个问题This site can’t be reached?