Home > Net >  Can't convert an object to a string
Can't convert an object to a string

Time:12-13

I filled up a dataframe with different file (each one containing data) I'm plotting some of the data through a loop to so I can see each series in a different color and also label each of them.

I'm facing a problem with the labeling. I'm accessing the values in a dataframe (column type: kv, vk, kvu etc etc). I guess my problem is either I'm attributing the row as the label or that I'm not able to convert the object in a string.

In the image, the result of the plot and I also printed through the result the variable I'm assigning to each plot legend that should be kv then kvu then uk then us....

code and results are taken from jupyter notebook I apologize if my description is not clear enough, this is my first post here

plt.figure(figsize=(8,6), dpi = 100)

le=le.sort_values(['layer number'], ascending=[True] )
for i in part:
    i=int(i)
    list_cli1 =list_cli0.loc[(list_cli["ID"] == i)]
    print(repr(list_cli1.type))
    #cli_type=list_cli1['type'].tolist
    #print(cli_type)
    le_part=le.loc[(le["part"] ==i)]
    plt.plot(le_part['layer number'], le_part['length'], label='part_' str(i) '_type_' str(list_cli1['type']))
    plt.xlabel('layer')
    plt.ylabel('nb pts >' str(maximus))
mplcursors.cursor()
plt.legend()

plt.show()

enter image description here

CodePudding user response:

I'm adding a picture of the dataframe... very simple to access.

enter image description here

CodePudding user response:

To get the column content as a string without its dtype try

list_cli1['type'].values 

or

list_cli1['type'].values[0]
  • Related