Location>code7788 >text

『Play Streamlit』--Data Display Component

Popularity:793 ℃/2024-11-13 13:46:33

The data presentation component in theStreamlitcomponents of all kinds occupies a vital place in the

Its core function is to present data in an intuitive, easy-to-understand way.

The data presentation components in this presentationcap (a poem)It can present complex data sets clearly in the form of tables, charts, etc., enabling users to quickly grasp the overall situation and detailed characteristics of the data.

1.

Presented in an easy-to-read and aesthetically pleasing mannerpandas(used form a nominal expression)DataFrame

Whether you're working with small datasets or huge tables of data, theBoth can display data with ease.

Ideal for scenarios where complex data sets need to be presented in a web application.

First, it automatically adapts to the width of the screen and supports horizontal or vertical scrolling, ensuring that users can easily navigate through the entire dataset.

In addition.Operations such as sorting, filtering and searching data are also supported, enhancing the readability and interactivity of the data.

2.

is also used to display tabular data in web applications, the

It can display interactive forms and offers a wide range of customization settings to meet all types of needs.

together withCompare.More applicable whenThe dataset is not particularly largeand need to maintain a clear and readable scene.

It allows the user to adjust the display of the table, such as column width, row height, etc. through simple configuration.

3. Distinction between the two

Both components are used to present data, and both support multiple types of data objects as input, such as theIterabledictAnd so on.

However, in the case ofinteractivityDisplay Modecap (a poem)feature richnessThere's a difference up there.

The following is an example to demonstrate the difference in the use of the two.

prior use Displays a static containing user informationDataFrame, such as name, age and email.

DataFramewill be displayed as a scrollable, sortable and searchable table. It is also possible to save data asCSVDocumentation.

Also used to display the same dataset of user information, but with a cleaner table style and relatively little functionality (e.g., no support for search).

import streamlit as st
import pandas as pd

# Create a static dataset
data = {
    "Name": ["ZhangSan", "LiSi", "WangFu"],
    
    "Mailbox": ["zhangsan@", "lisi@", "wangwu@"],
}
df = (data)

("")
# Use the display
(df)

("")
# Use the display
(df)

In addition to being more feature-rich, theFor displaying large datasets of thousands of rows, the height and width can be adjusted, and the data can be searched, filtered, and sorted, making it easier to view the data.

(indicates contrast)Due to the relative simplicity of the functionality, all data will be displayed directly, and it is not so convenient to browse and analyze large amounts of data.

For example, the following simulates a scenario with 10,000 pieces of data.

When displaying, a piece can be fixed in position; andDisplaying all the data flat down also took significantly longer to add.

# Create large data sets
(0)
data = {
    "ID": (1, 10001),
    "value1": (10000),
    "value2": (10000), # create large dataset (0)
    # ... More columns can be added
}
df = (data)

("", width=400, height=600)
# Display large datasets using
(df)

("")
# Use show large dataset (may not perform well)
# May not be optimal for large datasets
(df)

4. Summary

Overall. better suited to scenarios that require advanced functionality and dynamic interactions.

(indicates contrast) Then it is more suitable for simple, quick table presentations.