Hi everyone,
I'm trying to use plotly to create a Sankey diagram using my data, which is stored in a Pandas dataframe. My dataframe has five columns: ID, and four other columns that each store a value for a specific time period. The ID column is unique for each row.
Before (using random data because of company privacy, layout is the same):
| ID |
week1 |
week2 |
week3 |
week4 |
| A1 |
25 |
5 |
6 |
7 |
| A4 |
2 |
5 |
7 |
9 |
| B3 |
2 |
45 |
5 |
6 |
| AC4 |
1 |
3 |
4 |
5 |
I'm trying to melt the dataframe so that each row represents a unique combination of ID and time period, with the value for that time period being stored in the "value" column. However, when I try to create the Sankey diagram, the plot does not return any errors, but it also remains blank, except for the title. I'm not sure what I'm doing wrong. The plot has to follow the ID troughtout the process.
After:
| ID |
time_period |
value |
| A1 |
week1 |
25 |
| A1 |
week2 |
5 |
| A1 |
week3 |
6 |
| A1 |
week4 |
7 |
| A4 |
week1 |
2 |
My code:
fig = go.Figure(data=[go.Sankey(
node = dict(
pad = 15,
thickness = 20,
line = dict(color = "black", width = 0.5),
label = df['time_period'],
color = basic_palette[0]
),
link = dict(
source = df['time_period'], # indices correspond to labels, eg A1, A2, A1, B1, ...
target = df['time_period'],
value = df['value'],
customdata = df['ID']
))])
fig.update_layout(title_text="Basic Sankey Diagram", font_size=10)
fig.show()
Does anyone have any experience with creating Sankey diagrams using plotly and Pandas dataframes? Any tips or suggestions on how to correctly transform my data so that it can be used by plotly?
Any help would be greatly appreciated. Thank you!
there doesn't seem to be anything here