TypeError: bar_chart() got an unexpected keyword argument 'x'

  1. I am running my app locally.
  2. I don’t have github repository
  3. streamlit==1.10.0, , Python==3.6.8

I have Pandas dataframe with some columns with numbers and one column is the name of the months, corresponding to the index:

{
“Network Devices”: {
“8”: 100,
“9”: 130,
“10”: 220,
“11”: 537,
“12”: 643
},
“Total IPs”: {
“8”: 430,
“9”: 540,
“10”: 750,
“11”: 820,
“12”: 1280
},

“Month”: {
“8”: “August”,
“9”: “September”,
“10”: “October”,
“11”: “November”,
“12”: “December”
}
}

I am trying to create a bar chart for every column with the month name as X axis.
This code below works and creates nice bar charts with the index as X-axis and proper Y-axis values:

for col in df.columns:
    if col != ‘Month’ :
      st.bar_chart(data=df_mean[col])

Every time I am trying to add “x=…” parameter to st.bar_chart like
st.bar_chart(data=df[col], x=df[‘Month’])
I have error:

**TypeError: bar_chart() got an unexpected keyword argument ‘x’

Traceback:

File "/home/denis/DevInt/.venv/lib64/python3.6/site-packages/streamlit/scriptrunner/script_runner.py", line 554, in _run_script
    exec(code, module.__dict__)
File "/home/denis/DevInt/pages/StatPage.py", line 58, in <module>
    st.bar_chart(data=df[col], x=df['Month'])

**

What I am doing wrong?

I still don’t know why I am having this error, but I found the following workaround for my purpose:

  1. Inside the cycle I create a new temporarily dataframe from the original dataframe with only two columns, one of them is ‘Month’.
  2. Then I create a bar chart from this temp dataframe using ‘altair’
    For anybody who is interested, the working code is below:

    for col in df.columns:
       if col != ‘Month’ :
         # Create a new dataframe with columns ‘Month’ and col
          new_df = df[[‘Month’, col]].copy()
          # Plot the bar chart
          tittle = col + " average by month"
          chart = alt.Chart(new_df).mark_bar().encode(
             x=alt.X(‘Month’, sort=None),
             y=col
          ).properties(
             title={
                “text”: [tittle],
               “fontSize”: 18,
               “fontWeight”: “bold”,
                “subtitleFontSize”: 14,
               “subtitleFontWeight”: “normal”,
               “anchor”: “start”,
               “color”: “black”
             }
          )
          # Show the chart
          st.altair_chart(chart, use_container_width=True)