Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Support using DataFrame index for colors, labels, x, y, etc. #126

Closed
jason-curtis opened this issue Jul 31, 2019 · 8 comments
Closed

Support using DataFrame index for colors, labels, x, y, etc. #126

jason-curtis opened this issue Jul 31, 2019 · 8 comments

Comments

@jason-curtis
Copy link

I often use the DataFrame index for something meaningful, such as a timestamp corresponding to when the data was taken, or a sequence number. In those cases, it'd be great to be able to use that in plotly express to determine the X value, data color, text label, etc.

Currently the workaround is to copy the index to a separate column, e.g.

# Contrived example, but this usually comes from some other system
df = pd.DataFrame({'y': [1,2,3]}, index=[4,5,6])
df['x'] = df.index

px.scatter(df, x=px.INDEX, y='y')

Instead of having to change the DataFrame, it would be nice if I could just go ahead and do something like

df = pd.DataFrame({'y': [1,2,3]}, index=[4,5,6])
px.scatter(df, x=px.INDEX, y='y')

or even, in the special case of using it as an X value, it could be the default:

px.scatter(df, y='y')
@nicolaskruchten
Copy link
Contributor

We will try to support some version of this in an upcoming release. Most likely not the default behaviour with x and most likely not with a special px.INDEX value. I'm hoping to accept column/index references directly like px.scatter(df, x=df.index, y=df.col2) kind of thing :)

@jason-curtis
Copy link
Author

ooh, that sounds great. You could almost make the df argument optional then...
In the example you provided, would the x axis label then come from the df.index.name attribute or something?

Is there somewhere better for me to follow/comment on your progress towards this, or is this thread the right place to watch?

@nicolaskruchten
Copy link
Contributor

It's kind of spread out over a few issues ATM: #37 and #85

@nicolaskruchten
Copy link
Contributor

My intention is to create a PR and then update all the relevant issues :) Hopefully in the next month or so!

@jason-curtis
Copy link
Author

jason-curtis commented Aug 1, 2019

Awesome. Following those too. lmk if there's any kind of support I can provide.

@nicolaskruchten
Copy link
Contributor

In the example you provided, would the x axis label then come from the df.index.name attribute or something?

I could do that, yeah, if it's there, otherwise it would default to either "x" or "index" (undecided)

@nicolaskruchten
Copy link
Contributor

This will be implemented as part of plotly/plotly.py#1767 ... thanks for the input and patience :)

@nicolaskruchten
Copy link
Contributor

We've actually gone farther and implemented full wide-mode support: https://medium.com/plotly/beyond-tidy-plotly-express-now-accepts-wide-form-and-mixed-form-data-bdc3e054f891

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants