dg.add_rows - 追加数据行
DeltaGenerator
的add_rows
方法为现有数据追加数据行。
方法原型
DeltaGenerator.add_rows(data=None, **kwargs)
参数:
- data:要追加的数据表,类型可以是:
- pandas.DataFrame
- pandas.Styler
- numpy.ndarray
- Iterable
- dict
- None
- **kwargs:同上,只是采用关键字参数格式
示例代码
>>> df1 = pd.DataFrame(
... np.random.randn(50, 20),
... columns=('col %d' % i for i in range(20)))
...
>>> my_table = st.table(df1)
>>>
>>> df2 = pd.DataFrame(
... np.random.randn(50, 20),
... columns=('col %d' % i for i in range(20)))
...
>>> my_table.add_rows(df2)
>>> # Now the table shown in the Streamlit app contains the data for
>>> # df1 followed by the data for df2.
也可以为图表添加数据。例如:
>>> # Assuming df1 and df2 from the example above still exist...
>>> my_chart = st.line_chart(df1)
>>> my_chart.add_rows(df2)
>>> # Now the chart shown in the Streamlit app contains the data for
>>> # df1 followed by the data for df2.
如果图表使用命名数据集,你可以使用关键字参数传入:
>>> my_chart = st.vega_lite_chart({
... 'mark': 'line',
... 'encoding': {'x': 'a', 'y': 'b'},
... 'datasets': {
... 'some_fancy_name': df1, # <-- named dataset
... },
... 'data': {'name': 'some_fancy_name'},
... }),
>>> my_chart.add_rows(some_fancy_name=df2) # <-- name used as keyword