KeyError: 0 with bar chart

I have KeyError: 0
def display_bar_chart(data_copy):
st.bar_chart(data_copy, x=‘jour’, y='NBR De vente ', color=‘le nom’)
def DataSelection(Data,keyword):
options=set(Data[keyword])
label="Quel “+ keyword+ " souhaitez-vous afficher ?”
Branch=st.selectbox(label=label,options=options)

it raise this error:
KeyError: 0
Traceback:
File “C:\Users\koko\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\streamlit\runtime\scriptrunner\script_runner.py”, line 534, in _run_script
exec(code, module.dict)
File “C:\Users\koko\maroc.py”, line 75, in
main()
File “C:\Users\koko\maroc.py”, line 72, in main
display_bar_chart(selected_data)
File “C:\Users\koko\maroc.py”, line 53, in display_bar_chart
st.bar_chart(data_copy, x=‘jour’, y='NBR De vente ', color=‘le nom’)
File “C:\Users\koko\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\streamlit\runtime\metrics_util.py”, line 396, in wrapped_func
result = non_optional_func(*args, **kwargs)
File “C:\Users\koko\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\streamlit\elements\arrow_altair.py”, line 559, in bar_chart
chart, add_rows_metadata = _generate_chart(
File “C:\Users\koko\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\streamlit\elements\arrow_altair.py”, line 972, in _generate_chart
df, x_column, y_column, color_column, size_column = prep_data(
File “C:\Users\koko\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\streamlit\elements\arrow_altair.py”, line 907, in prep_data
_maybe_convert_color_column_in_place(selected_data, color_column)
File “C:\Users\koko\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\streamlit\elements\arrow_altair.py”, line 1064, in _maybe_convert_color_column_in_place
first_color_datum = df[color_column][0]
File “C:\Users\koko\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pandas\core\series.py”, line 1007, in getitem
return self._get_value(key)
File “C:\Users\koko\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pandas\core\series.py”, line 1116, in _get_value
loc = self.index.get_loc(label)
File “C:\Users\koko\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pandas\core\indexes\base.py”, line 3655, in get_loc
raise

Hey @koko1998,

Pleaseformat your code properly for better readability (check out #3 in our forum guidelines for instructions on formatting code) and update your post to include a link to your GitHub repo and a link to your deployed app (if it’s deployed).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.