After that you can use your dataframe, because it now exists outside of the your function.
This is my problem: Cousera course on Apllied Data Science in Python I am doing Assigment 2.
Question 1 Which country has won the most gold medals in summer games? This function should return a single string value.
This my code:
def answer_one():
return df[df['Gold'] == df['Gold'].max()].index(0)
answer_one()
This is the error which I am getting:
NameError: name 'df' is not defined
def func_nb():
data = pd.read_csv('dummycsv.csv')
df = DataFrame(data)
df['Tag'] = df['Tag'].map(lambda x: re.sub(r'\W+', '_', x))
return df
df = func_nb()
After that you can use your dataframe, because it now exists outside of the your function.
import streamlit as st
import pandas as pd
from pandas import DataFrame
import matplotlib.pyplot as plt
import plotly.express as px
#configuration
st.set_option('deprecation.showfileUploaderEncoding', False)
st.title("Data Visualisation App")
# Add sidebar
st.sidebar.subheader("Visualisation settings")
# Setup file upload
global df
uploaded_file = st.sidebar.file_uploader(label="Upload your Excel file", type = ['csv','xlsx'])
if uploaded_file is not None:
df = pd.read_csv(uploaded_file)
st.write("Data Set")
st.dataframe(df,3000,500)
if st.checkbox('Show raw data'):
st.subheader('Raw data')
st.write(df)
func_nb()
return the df and make sure to call the function func_nb()
Please try to use .Hope so it will work
return df['Gold'].idxmax()