'How to plot some rows from 2 different columns in Pandas DataFrame?

I have been trying to plot 2 different columns by row index, but I haven't been able to do it. data set

I need to plot 'mean train score' vs 'param hidden' keeping 'param activation' and 'param alpha' constant. so I thought I could slice the DataFrame by rows but the 'param hidden' values are tuples and it gives me an error. what can I do?



Solution 1:[1]

Extract the value from the tuples in "param hidden:"

df['param hidden extracted'] = [t[0] for t in df['param hidden]]

Then create new column that contains both "param activation" and "param alpha" and use it as a grouping column:

df['group param'] = [f'{alpha} {activation}' for alpha, activation in zip(df['param alpha], df['param activation])]

Using Plotly Express, plot the line with "group param" as the color:

import plotly.express as px

fig = px.line(df, x="mean train score", y="param hidden extracted", color='group param')
fig.show()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Charles Yang