过滤和修改数据帧的dash脚本会发出警告

问题描述 投票:0回答:0

我有以下脚本

import dash
from dash import dcc, html
from dash.dependencies import Input, Output
import pandas as pd


# The warning has not been resolved

# Sample DataFrame
data = {
    'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Eve'],
    'Age': [25, 30, 22, 35, 28],
    'Salary': [50000, 60000, 45000, 70000, 55000]
}

df = pd.DataFrame(data)

app = dash.Dash(__name__)

app.layout = html.Div([
    html.H1("DataFrame Filtering and Augmentation"),

    html.Label("Filter by Age:"),
    dcc.Input(id='age-filter', type='number', value=30),

    dcc.Graph(id='result-plot')
])

@app.callback(
    Output('result-plot', 'figure'),
    [Input('age-filter', 'value')]
)
def update_dataframe(age_filter):
    # Filter the DataFrame based on age
    filtered_df = df[df['Age'] < age_filter]

    # Augment the filtered DataFrame with a new column
    filtered_df['SalarySquared'] = filtered_df['Salary'] ** 2

    # Create a bar chart based on the augmented DataFrame
    figure = {
        'data': [
            {'x': filtered_df['Name'], 'y': filtered_df['SalarySquared'], 'type': 'bar', 'name': 'Salary Squared'},
        ],
        'layout': {
            'title': f'Salary Squared for Individuals with Age < {age_filter}',
            'xaxis': {'title': 'Name'},
            'yaxis': {'title': 'Salary Squared'}
        }
    }

    return figure

if __name__ == '__main__':
    app.run_server(debug=True,port=8070)

尽管这个脚本可以工作并且给了我我需要的东西,但它显示了一个警告

Dash 运行于 http://127.0.0.1:8070/

  • 服务 Flask 应用程序“cashFilterCalculations”
  • 调试模式:开

C:\帕特

python pandas plotly-dash
© www.soinside.com 2019 - 2024. All rights reserved.