shao
This commit is contained in:
parent
6690f10e44
commit
c9969f62fb
|
@ -0,0 +1,9 @@
|
|||
import plotly.graph_objects as go
|
||||
from nicegui import ui
|
||||
|
||||
fig = go.Figure(go.Scatter(x=[1, 2, 3, 4], y=[1, 2, 3, 2.5]))
|
||||
fig.update_layout(margin=dict(l=0, r=0, t=0, b=0))
|
||||
plot = ui.plotly(fig).classes('w-full h-40')
|
||||
plot.on('plotly_click', ui.notify)
|
||||
|
||||
ui.run()
|
|
@ -0,0 +1,15 @@
|
|||
import plotly.graph_objects as go
|
||||
from nicegui import ui
|
||||
from random import random
|
||||
|
||||
fig = go.Figure()
|
||||
fig.update_layout(margin=dict(l=0, r=0, t=0, b=0))
|
||||
plot = ui.plotly(fig).classes('w-full h-40')
|
||||
|
||||
def add_trace():
|
||||
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[random(), random(), random()]))
|
||||
plot.update()
|
||||
|
||||
ui.button('Add trace', on_click=add_trace)
|
||||
|
||||
ui.run()
|
|
@ -0,0 +1,27 @@
|
|||
import plotly.graph_objects as go
|
||||
from nicegui import ui
|
||||
from random import random
|
||||
|
||||
|
||||
ui.label('登录系统')
|
||||
x = ui.input(label='x:')
|
||||
y = ui.input(label='y:')
|
||||
z = ui.input(label='z:')
|
||||
|
||||
|
||||
|
||||
fig = go.Figure()
|
||||
fig.update_layout(margin=dict(l=0, r=0, t=0, b=0))
|
||||
plot = ui.plotly(fig).classes('w-full h-40')
|
||||
|
||||
def add_trace():
|
||||
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[x.value, y.value, z.value]))
|
||||
plot.update()
|
||||
|
||||
ui.button('Add trace', on_click=add_trace)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ui.run()
|
|
@ -0,0 +1,19 @@
|
|||
from nicegui import ui
|
||||
import pandas as pd
|
||||
|
||||
# 创建一个简单的DataFrame
|
||||
data = {
|
||||
'Name': ['Alice', 'Bob', 'Charlie'],
|
||||
'Age': [25, 30, 35],
|
||||
'City': ['New York', 'Paris', 'London']
|
||||
}
|
||||
df = pd.DataFrame(data)
|
||||
|
||||
|
||||
# 在nicegui中创建并显示表格
|
||||
|
||||
ui.label('显示DataFrame')
|
||||
ui.table.from_pandas(df).classes('max-h-40')
|
||||
|
||||
# 启动应用
|
||||
ui.run()
|
|
@ -0,0 +1,23 @@
|
|||
from nicegui import ui
|
||||
|
||||
# 设置正确的用户名和密码,仅用于演示目的
|
||||
CORRECT_USERNAME = 'user'
|
||||
CORRECT_PASSWORD = 'password'
|
||||
|
||||
# 定义登录函数
|
||||
def on_login():
|
||||
# 检查用户名和密码是否正确
|
||||
if username_input.value == CORRECT_USERNAME and password_input.value == CORRECT_PASSWORD:
|
||||
login_status.text = '登录成功!' # 使用 .text 属性更新文本
|
||||
else:
|
||||
login_status.text = '登录失败,请检查您的用户名和密码。' # 使用 .text 属性更新文本
|
||||
|
||||
# 创建UI元素
|
||||
ui.label('登录系统')
|
||||
username_input = ui.input(label='用户名:')
|
||||
password_input = ui.input(label='密码:') # 使用 type='password' 使密码输入不可见
|
||||
ui.button('登录', on_click=on_login)
|
||||
login_status = ui.label('请进行登录') # 初始提示文本
|
||||
|
||||
# 启动应用
|
||||
ui.run()
|
|
@ -1,7 +1,14 @@
|
|||
import plotly.express as px
|
||||
import pandas
|
||||
df = px.data.gapminder()
|
||||
df1 = df.query("country == 'United States'")
|
||||
df1 = df.query("country == 'United States' or continent == 'Asia'")
|
||||
|
||||
|
||||
# 根据大陆对数据进行分组,并计算每个大陆的人均GDP平均值
|
||||
gdpPercap_summary = df.groupby('continent')[['gdpPercap','lifeExp']].mean().reset_index()
|
||||
|
||||
# 显示结果
|
||||
print(gdpPercap_summary)
|
||||
|
||||
print(df1.columns)
|
||||
fig = px.line(df1,
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -9,7 +9,7 @@ data = {
|
|||
'Sales': [100, 150, 120, 110, 130, 120]
|
||||
}
|
||||
df = pd.DataFrame(data)
|
||||
grouped_df = df.groupby('Product')['Sales'].sum()
|
||||
grouped_df = df.groupby(by = 'Product')['Sales'].sum()
|
||||
print(grouped_df)
|
||||
# 这个操作将按照Product列进行分组,并计算每个分组中Sales列的总和,从而得到每个产品的总销售额。
|
||||
# 这意味着产品A的总销售额为350,而产品B的总销售额为380。通过使用groupby方法,我们能够轻松地按照Product列对数据进行分组,并计算每个分组的Sales列总和,从而得到每个产品在所有日期上的总销售额。这个例子展示了groupby方法在数据分析和处理中的强大功能和灵活性
|
||||
|
|
Loading…
Reference in New Issue