How to make data pass through: pandas.errors.InvalidIndexError: (slice()...)

I’ve reached a point where I don’t know what else to do.

I have this df

dff8df      !!!0 WWSF   VPIP   VPIP   VPIP
0         52.0  38.64  38.64  38.64
1         62.0  50.00  50.00  50.00
2         73.0  56.25  56.25  56.25
3         99.0  23.08  23.08  23.08
4         30.0  41.67  41.67  41.67
..         ...    ...    ...    ...
540       50.0  18.75  18.75  18.75
541       99.0  26.32  26.32  26.32
542       50.0  28.57  28.57  28.57
543       83.0  14.29  14.29  14.29
544       57.0  38.89  38.89  38.89

[545 rows x 4 columns]

and this code:

print("dff8df",dff8)

    figure = px.scatter(data_frame=dff8,
                   x=dff8[:,drop1],
                   y=dff8[:,drop2],
                   color=dff8[:,drop4],
                   size=dff8[:,drop3],
                   trendline="ols",
                   trendline_color_override="red",
                   title="%s vs %s"%(drop1, drop2),
                   )

and it gives this error with plotly in python:

pandas.errors.InvalidIndexError: (slice(None, None, None), 'VPIP')

How can I solve this problem?

Could you provide more information on drop1, drop2, drop3, drop4, and dff8.columns?

drop1,drop2… are the names of the columns … and dff8 (printed dff8df) is the df

I meant could you give the actual values you have set to those variables, and list what output you get for executing dff8.columns? It’s strange that you have multiple columns with the same name. Try giving each column a unique name.

I found a solution.

I droped columns, and put the names of the columns (drop1,2,3 … they are an argument of a callback) to list …

but now, with another chart, I’m getting a problem, because with only 1 column, I cant do a .tolist

I used this, to solve first chart:

drop1, drop2, drop3, drop4, drop5 = dfff2.columns[0:5].tolist()

This is a bit outside of the scope of this forum, but for a pandas series, you can get the “column” name by calling dfff3.name. Also, you shouldn’t need to call to_list() for drops 1-4 either.

1 Like