Home > Blockchain >  How to plot a dataframe column of lists as horizontal lines
How to plot a dataframe column of lists as horizontal lines

Time:11-08

I have a Dataframe with the column 'all_maxs' that could have a list of different values.

          c            all_maxs
38  50804.6           [50883.3]
39  50743.9           [50883.3]
40  50649.9           [50883.3]
41  50508.3           [50883.3]
42  50577.6           [50883.3]
43  50703.0           [50883.3]
44  50793.7           [50883.3]
45  50647.8  [50883.3, 50813.1]
46  50732.8  [50883.3, 50813.1]
47  50673.2  [50883.3, 50813.1]

df.plot(y='c')

Current Result

enter image description here

I need to plot column 'c', and the values of column 'all_maxs' that should be horizontal lines.

Expected Result

expected result

CodePudding user response:

  1. Verify the 'all_maxs' values are list type.
  2. Extract values from the lists and plot them as horizontal lines.
    • df = df.dropna() if there are any NaN

Imports and DataFrame

  • Convert the 'all_maxs' column type from str to list if needed, using enter image description here

  • Related