-2

I have been trying to extract some data from a DataFrame, where I ran into this issue. While I am trying to plot a line plot using matplotlib.plot (column_name) The DataFrame had the column name " Ladder score" But this cannot be executed in the matplotlib plot function, we can't use space between words. But the given column in DataFrame has the column name like that. How can I overcome this issue?

Image of error:

image of error

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Ibu
  • 11
  • 1
  • Access to the error is denied for me (may need to make it available to anyone with the link) – cmay Nov 07 '21 at 02:59
  • 2
    Please include any relevant information [as text directly into your question](https://stackoverflow.com/editing-help), do not link or embed external documents. We expect images to be self contained. – Henry Ecker Nov 07 '21 at 03:03
  • Changed the permission now and I can't upload any image here, showing that "I can't do that" – Ibu Nov 07 '21 at 03:04
  • 1
    The main point of Henry's comment is that [code/errors/data should be pasted **as text,** not images](https://meta.stackoverflow.com/a/285557/13138364). – tdy Nov 07 '21 at 03:12
  • I have edited your question and moved the hosting of the image from Google Drive to Stack Overflow. That said we prefer no images at all when it can be represented as text. [How to make good reproducible pandas examples](https://stackoverflow.com/q/20109391/15497888) provides some guidance on how to provide a small sample DataFrame. – Henry Ecker Nov 07 '21 at 03:35
  • 1
    the dot-accessor of columns in a dataframe is for convenience only, and works only when the names are valid python identifiers – Paul H Nov 07 '21 at 03:47
  • `df.columns = df.columns.str.strip()` to remove whitespace at the beginning and end, and then `df.columns = df.columns.str.replace(' ', '_')` to replace spaces with underscores. – Trenton McKinney Nov 07 '21 at 12:24

1 Answers1

0

Just call your plot using

plt.plot(b[" Ladder score"])
cmay
  • 153
  • 6