'Struggling with turning data into an array to delete columns

I get the error "builtins.TypeError: cannot perform reduce with flexible type" and i use this code to convert the data into an array and delete specific columns

def boxplot_data(data, output_name= plt.savefig('output.png')):
    
    print(data)
    data = np.asarray([data])
    data = np.delete(data, [0,1,7,8], 1) 

an example of my data is

('2020-02-26 12:14:55', '1232640183658582021', 0.456, 0.398, 0.463, 0.44 , 0.25 , 'negative', 'fear')
('2020-02-26 19:15:00', '1232745898767245312', 0.541, 0.377, 0.433, 0.342, 0.479, 'positive', 'joy')
('2020-02-28 04:38:47', '1233250168344109057', 0.349, 0.511, 0.595, 0.509, 0.187, 'negative', 'fear')
('2020-02-28 07:01:20', '1233286044382048257', 0.497, 0.398, 0.436, 0.351, 0.312, 'neutral', 'no specific emotion')
('2020-02-26 20:40:04', '1232767308860461058', 0.314, 0.645, 0.547, 0.535, 0.118, 'negative', 'anger')
('2020-02-13 13:27:15', '1227947345104343040', 0.396, 0.514, 0.573, 0.479, 0.23 , 'negative', 'fear')
('2020-02-29 18:03:23', '1233815042598068226', 0.598, 0.266, 0.165, 0.262, 0.395, 'positive', 'joy')


Solution 1:[1]

You might want something like:

def boxplot_data(data, output_name='output.png'):
    data = np.asarray(data)
    data = np.delete(data, [0,1,7,8], 1)
    data = data.astype(float)
    print(data)
    import matplotlib.pyplot as plt 
    plt.boxplot(data)
    plt.savefig(output_name)
    
boxplot_data(data)

Output:

[[0.456 0.398 0.463 0.44  0.25 ]
 [0.541 0.377 0.433 0.342 0.479]
 [0.349 0.511 0.595 0.509 0.187]
 [0.497 0.398 0.436 0.351 0.312]
 [0.314 0.645 0.547 0.535 0.118]
 [0.396 0.514 0.573 0.479 0.23 ]
 [0.598 0.266 0.165 0.262 0.395]]

Figure:

enter image description here

Used input;

data=[
('2020-02-26 12:14:55', '1232640183658582021', 0.456, 0.398, 0.463, 0.44 , 0.25 , 'negative', 'fear'),
('2020-02-26 19:15:00', '1232745898767245312', 0.541, 0.377, 0.433, 0.342, 0.479, 'positive', 'joy'),
('2020-02-28 04:38:47', '1233250168344109057', 0.349, 0.511, 0.595, 0.509, 0.187, 'negative', 'fear'),
('2020-02-28 07:01:20', '1233286044382048257', 0.497, 0.398, 0.436, 0.351, 0.312, 'neutral', 'no specific emotion'),
('2020-02-26 20:40:04', '1232767308860461058', 0.314, 0.645, 0.547, 0.535, 0.118, 'negative', 'anger'),
('2020-02-13 13:27:15', '1227947345104343040', 0.396, 0.514, 0.573, 0.479, 0.23 , 'negative', 'fear'),
('2020-02-29 18:03:23', '1233815042598068226', 0.598, 0.266, 0.165, 0.262, 0.395, 'positive', 'joy'),
]

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 mozway