Conversation
Changing the data type to str in order to avoid the "("Expected bytes, got a 'int' object", 'Conversion failed for column FG% with type object')" error by the st.dataframe on line 45.
This is a new error introduced in streamlit v.85.
There was a problem hiding this comment.
Proposed (2) Minor .py File Changes
Hello DataProf,
I sincerely appreciate and thank you for great content and tutorials. As noted in the YT video (https://youtu.be/JwSS70SZdyM) comments section, this script has presented an error for several users. I hope you will please consider the following 2 small revisions to resolve 1 error and 1 warning with App03 - basketball_app.py.
1). To resolve error "("Expected bytes, got a 'int' object", 'Conversion failed for column FG% with type object')" - Please consider a small change to wrap/typecast df_selected_team in line 40 as string prior to use of df_selected_team in line 44. (NOTE* - The existing PR (thank you to odagayev) that adds another line of code however I wish to suggest wrapping the existing assignment to avoid addition of another line of code.)
Proposed Change of Line 40
from
df_selected_team = playerstats[(playerstats.Tm.isin(selected_team)) & (playerstats.Pos.isin(selected_pos))]
to
df_selected_team = (playerstats[(playerstats.Tm.isin(selected_team)) & (playerstats.Pos.isin(selected_pos))]).astype(str)
2). To resolve deprecation warning when clicking the "Intercorrelation Heatmap" button - PyplotGlobalUseWarning: You are calling st.pyplot() without any arguments. Please consider 1 character modification to line 68 to explicitly pass f (figure) as a parameter to resolve warning.
Proposed Change of Line 68
from
st.pyplot()
to
st.pyplot(f)
Surely if these are erroneous, present issue(s) or there is a simpler solution, please. I thank you in advance for your time and consideration.
Sincerely,
JDHaus
|
Hello.
The code would be: # Heatmap
if st.button('Intercorrelation Heatmap'):
st.header('Intercorrelation Matrix Heatmap')
df_selected_team.to_csv('output.csv',index=False)
df = pd.read_csv('output.csv')
#Dropping Non-Numerical (string) Columns
df_selected_htmp = df.drop(columns=['Player', 'Pos', 'Tm'], axis=1)
# corr = df.corr()
corr = df_selected_htmp.corr()
mask = np.zeros_like(corr)
mask[np.triu_indices_from(mask)] = True
with sns.axes_style("white"):
f, ax = plt.subplots(figsize=(7, 5))
ax = sns.heatmap(corr, mask=mask, vmax=1, square=True)
st.pyplot(f) |
Changing the data type to str in order to avoid the "("Expected bytes, got a 'int' object", 'Conversion failed for column FG% with type object')" error by the st.dataframe on line 45.
This is a new error introduced in streamlit v.85.