Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update basketball_app.py #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

odagayev
Copy link

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.

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.
Copy link

@jdhauswirth jdhauswirth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proposed (2) Minor .py File Changes

https://github.com/jdhauswirth/streamlit_freecodecamp/blob/main/app_3_eda_basketball/basketball_app.py

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

@Luismbpr
Copy link

Luismbpr commented Oct 12, 2023

Hello.
I propose the following minor changes. This is to make sure there are no conflicts regarding strings on the correlation so the heat map is displayed.

  1. Dropping the non-numerical columns (Player, Position and Team) from the re-uploaded DataFrame.
  2. Adding the st.pyplot(f) so the figure shows correctly.

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants