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

x polymorphism for index and series type #37

Closed
yytsui opened this issue Mar 29, 2019 · 7 comments
Closed

x polymorphism for index and series type #37

yytsui opened this issue Mar 29, 2019 · 7 comments

Comments

@yytsui
Copy link

yytsui commented Mar 29, 2019

This will be useful for time series data.
Instead of copy time index to a column:

df['time'] = df.index
px.line(df, x='time', y='value')

it will be more convenient that we can do this directly:

px.line(df, x=df.index, y='value')

Thank you for this great library!

@jonmmease
Copy link
Contributor

One consideration here is that plotly_express needs a name associated with each column for things like axis labels and hover tooltips.

Pandas index levels can optionally have names, and I would be in favor of having plotly_express search the index levels if a specified name doesn't show up as a column.

If the index doesn't already have a name then a name would need to be assigned, but this doesn't require duplicating data and I'd argue that it's a reasonable thing to do even apart from visualization.

Something like...

df.index.name = 'time'
px.line(df, x='time', y='value')

@nicolaskruchten
Copy link
Contributor

Interestingly, we could actually take things a bit farther: consider something px.line(df, x=df.index, y=df.cool_column). Given df, px could internally try to do equality checks on the columns and the index (assuming first col of index, say) and retrieve the names from df. This would allow-but-not-require Series to be passed in, thereby enabling some nice auto-complete behaviour... not just strings any more!

@mazzma12
Copy link

mazzma12 commented Apr 5, 2019

Hi there,

Just joined the issue, as I was talking about it somewhere else. As I mentioned it already, I suggest to call reset_index() on the series, WDYT ?

It's actually quite easy to grab the x and y column names from the series ts' by doing x=ts.index.nameandy=ts.name. Then when you call ts.reset_index()it will return a new dataframe object with columns [x, y]`

@nicolaskruchten
Copy link
Contributor

I don't really want to accept arbitrary Series as inputs here, I'd rather they belong to df, as anyway I'm using df.groupby() under the hood

@nicolaskruchten
Copy link
Contributor

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

@prasadsonar2
Copy link

what kind of datatypes supported to plotly

@nicolaskruchten
Copy link
Contributor

@prasadsonar2 here is the documentation on input arguments for Plotly Express: https://plot.ly/python/px-arguments/

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

5 participants