English 中文(简体)
How can I fix streamlit groupby.transform error?
原标题:
df1 = pd.DataFrame({ value : [1, np.nan, np.nan, 2, 3, 1, 3, np.nan, 3],  name : [ A , A ,  B , B , B , B ,  C , C , C ]})

df2 = pd.DataFrame({ value : [1, np.nan, np.nan, 2, 3, 1, 3, np.nan, 3],  name : [ A , A ,  B , B , B , B ,  C , C , C ]})


[ df1 ]
  name  value
0    A      1
1    A    NaN
2    B    NaN
3    B      2
4    B      3
5    B      1
6    C      3
7    C    NaN
8    C      3

[ df2 ]
  name  value
0    A      1
1    A    NaN
2    B    NaN
3    B      2
4    B      3
5    B      1
6    C      3
7    C    NaN

numeric_only_columns = df1.select_dtypes(exclude = [ object ,  datetime ]).columns.to_list()

for i in numeric_only_columns:
    df1[i] = df1[i].fillna(df1.groupby(groupby_columns)[i].transform( mean ))
    df2[i] = df2[i].fillna(df1.groupby(groupby_columns)[i].transform( mean ))



df2[i] = df2[i].fillna(df1.groupby(groupby_columns)[i].transform( mean )) working


my stremalit code

fill_na_columns = st.selectbox("select method?",( mean , min , max , median ))
                    groupby_columns = st.multiselect("Groupby columns select", train.columns.to_list(), default=train.columns.to_list()[0])

if fill_na_columns ==  mean :
   st.dataframe(train.groupby(groupby_columns).mean(numeric_only=True))
   numeric_only_columns = train.select_dtypes(exclude = [ object ,  datetime ]).columns.to_list()


    for i in numeric_only_columns:
                            train[i] = train[i].fillna(train.groupby(groupby_columns)[i].transform( mean ))
                            test[i] = test[i].fillna(train.groupby(groupby_columns)[i].transform( mean ))
                            val[i] = val[i].fillna(train.groupby(groupby_columns)[i].transform( mean ))

Applied to train but not to test and val .. Works fine on jupyter notebook but In streamlit, no values ​​are applied to test, val. why this happen?

Applied to train but not to test and val .. Works fine on jupyter notebook but In streamlit, no values ​​are applied to test, val. why this happen?

问题回答

暂无回答




相关问题
re-arrange data by pairs recursively

I have dataframe contains ACQ/REL pair recusively as below: import pandas as pd data = [ [ 2023-06-05 16:51:27.561 , ACQ , location ], [ 2023-06-05 16:51:27.564 , ACQ , location ], [ ...

Filling NAN values in Pandas by using previous values

I have a Pandas DataFrame in the following format. I am trying to fill the NaN value by using the most recent non-NaN value and adding one second to the time value. For example, in this case, the ...

Python/Pandas convert string to time only

I have the following Pandas dataframe in Python 2.7. import pandas as pd trial_num = [1,2,3,4,5] sail_rem_time = [ 11:33:11 , 16:29:05 , 09:37:56 , 21:43:31 , 17:42:06 ] dfc = pd.DataFrame(zip(*[...

Pretty-print an entire Pandas Series / DataFrame

I work with Series and DataFrames on the terminal a lot. The default __repr__ for a Series returns a reduced sample, with some head and tail values, but the rest missing. Is there a builtin way to ...

How to invert the x or y axis

I have a scatter plot graph with a bunch of random x, y coordinates. Currently the Y-Axis starts at 0 and goes up to the max value. I would like the Y-Axis to start at the max value and go up to 0. ...

热门标签