[英]How to create a plotly line plot from a pandas DataFrame with lists
[英]How to pipe plotly line plot to pandas dataframe?
我們如何使用.pipe()
來獲得有情節的表達線圖?
import numpy as np
import pandas as pd
import seaborn as sns
import plotly.express as px
df = pd.DataFrame(data={'count':np.random.randint(1,20,10)},
index=pd.date_range('2020-01-01','2020-01-10')
)
df1 = df.resample('2D').sum()
px.line(df1,x=df1.index,y='count')
這里創建 df1 是不必要的。 我們如何使用管道?
我的嘗試
df.resample('2D').sum().pipe(px.line,x=lambda x: x.index,y='count')
# this does not work, gives empty plot
如何獲得正確的圖像?
你很接近:
import numpy as np
import pandas as pd
import seaborn as sns
import plotly.express as px
df = pd.DataFrame(data={'count':np.random.randint(1,20,10)},
index=pd.date_range('2020-01-01','2020-01-10')
)
# line plot with pipe
df.resample('2D').sum().pipe(lambda ts:
px.line(ts, x=ts.index,y='count'))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.