通过 Plotly 或其他方式在一张图中绘制多个箱线图(一列是数据列表)
plot multiple boxplot in one graph ( one column is list of data) by Plotly or other way
我不知道如何通过 Plotly 在一张图中绘制多个箱线图。我想重点是 'list_hour' 列中的值是列表。我的数据框是这样的:
Main_Category list_hour
0 Active Life [22, 21, 18, 23, 20, 5, 13, 12, 20, 0, 22, 19,...
1 Auto Repair [17, 15, 19, 23, 16, 22, 22, 19, 15, 20, 18, 1...
2 Automotive [17, 18, 19, 0, 20, 5, 23, 17, 15, 18, 22, 16,...
3 Beauty & Spas [17, 18, 17, 0, 4, 16, 17, 23, 23, 23, 18, 2, ...
4 Event Planning & Services [22, 20, 1, 17, 1, 4, 18, 20, 18, 17, 21, 5, 2...
5 Fast Food [17, 2, 2, 2, 5, 5, 2, 2, 7, 10, 2, 2, 22, 1, ...
6 Food [21, 17, 0, 23, 5, 2, 3, 19, 22, 22, 0, 19, 22...
7 Hair Salons [17, 23, 18, 3, 0, 0, 23, 6, 23, 15, 19, 7, 3,...
8 Health & Medical [10, 21, 18, 18, 20, 14, 15, 22, 18, 23, 15, 1...
9 Home Services [2, 2, 3, 16, 4, 20, 14, 1, 2, 20, 2, 21, 7, 1...
10 Local Services [2, 17, 2, 15, 15, 15, 20, 21, 15, 17, 18, 1, ...
11 Nightlife [23, 13, 2, 1, 13, 3, 5, 19, 3, 3, 19, 22, 18,...
12 Pizza [18, 23, 0, 4, 20, 17, 3, 19, 2, 20, 20, 23, 4...
13 Restaurants [16, 0, 16, 16, 15, 21, 22, 18, 7, 15, 23, 1, ...
14 Shopping [0, 22, 18, 23, 17, 14, 21, 19, 2, 22, 3, 21, ...
或者有没有其他方法可以为这个数据框而不是 Plotly 绘制多个箱线图?感谢您的帮助!!!
这是我解决这个问题的方法。
nn = list_hour_df.explode('list_hour').reset_index(drop=True)
nn['list_hour'] = nn['list_hour'].astype(int)
nn
0 Active Life 22
1 Active Life 21
2 Active Life 18
3 Active Life 23
4 Active Life 20
... ... ...
396416 Shopping 8
396417 Shopping 13
396418 Shopping 21
396419 Shopping 19
396420 Shopping 4
fig = px.box(nn, x="list_hour", y="Main_Category")
fig.show()
enter image description here
我不知道如何通过 Plotly 在一张图中绘制多个箱线图。我想重点是 'list_hour' 列中的值是列表。我的数据框是这样的:
Main_Category list_hour
0 Active Life [22, 21, 18, 23, 20, 5, 13, 12, 20, 0, 22, 19,...
1 Auto Repair [17, 15, 19, 23, 16, 22, 22, 19, 15, 20, 18, 1...
2 Automotive [17, 18, 19, 0, 20, 5, 23, 17, 15, 18, 22, 16,...
3 Beauty & Spas [17, 18, 17, 0, 4, 16, 17, 23, 23, 23, 18, 2, ...
4 Event Planning & Services [22, 20, 1, 17, 1, 4, 18, 20, 18, 17, 21, 5, 2...
5 Fast Food [17, 2, 2, 2, 5, 5, 2, 2, 7, 10, 2, 2, 22, 1, ...
6 Food [21, 17, 0, 23, 5, 2, 3, 19, 22, 22, 0, 19, 22...
7 Hair Salons [17, 23, 18, 3, 0, 0, 23, 6, 23, 15, 19, 7, 3,...
8 Health & Medical [10, 21, 18, 18, 20, 14, 15, 22, 18, 23, 15, 1...
9 Home Services [2, 2, 3, 16, 4, 20, 14, 1, 2, 20, 2, 21, 7, 1...
10 Local Services [2, 17, 2, 15, 15, 15, 20, 21, 15, 17, 18, 1, ...
11 Nightlife [23, 13, 2, 1, 13, 3, 5, 19, 3, 3, 19, 22, 18,...
12 Pizza [18, 23, 0, 4, 20, 17, 3, 19, 2, 20, 20, 23, 4...
13 Restaurants [16, 0, 16, 16, 15, 21, 22, 18, 7, 15, 23, 1, ...
14 Shopping [0, 22, 18, 23, 17, 14, 21, 19, 2, 22, 3, 21, ...
或者有没有其他方法可以为这个数据框而不是 Plotly 绘制多个箱线图?感谢您的帮助!!!
这是我解决这个问题的方法。
nn = list_hour_df.explode('list_hour').reset_index(drop=True)
nn['list_hour'] = nn['list_hour'].astype(int)
nn
0 Active Life 22
1 Active Life 21
2 Active Life 18
3 Active Life 23
4 Active Life 20
... ... ...
396416 Shopping 8
396417 Shopping 13
396418 Shopping 21
396419 Shopping 19
396420 Shopping 4
fig = px.box(nn, x="list_hour", y="Main_Category")
fig.show()
enter image description here