Kindly need your support as i’m getting error after run code even i check if df is not None before run the code , but error dis appear after upload data
def loadData():
data =pd.DataFrame()
uploadFile= st.file_uploader("Choose output.csv file")
if uploadFile is not None:
df = pd.read_csv(uploadFile)
data = df
return data
df = loadData()
if df is not None:
def mergePop():
#appended pop list
popList=[]
#get US from df and get first 5 No to irritae
#usList = df['UserName'].to_list()
for us in df['UserName'] :
#us2=str(us)
#st.write(type(us2))
if us is not None:
if us[:2] == '02':
popList.append('Cairo')
elif us[:2] == '03':
popList.append('Alx')
else:
popList.append('NA')
popS= pd.Series(popList)
return popS
if df is not None:
df['pop']= pd.Series(mergePop())
st.dataframe(df)
----------------------
KeyError: 'UserName'
Traceback:
File "c:\anaconda3\envs\elbouhy-env\lib\site-packages\streamlit\script_runner.py", line 332, in _run_script
exec(code, module.__dict__)File "C:\Users\ramye\Desktop\test3.py", line 46, in <module>
df['pop']= pd.Series(mergePop())File "C:\Users\ramye\Desktop\test3.py", line 28, in mergePop
for us in df['UserName'] :File "c:\anaconda3\envs\elbouhy-env\lib\site-packages\pandas\core\frame.py", line 3024, in __getitem__
indexer = self.columns.get_loc(key)File "c:\anaconda3\envs\elbouhy-env\lib\site-packages\pandas\core\indexes\base.py", line 3082, in get_loc
raise KeyError(key) from err