Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Statistics.median converting lists containing float numbers into integers

Here is a list, containing different integers, and floats, strings. I want to find the median numbers using statistics.median() but I cannot convert the list into integers.

#DOCTYPE Python 
import statistics
import numpy as np
data = ['3900000.00', '140000000.00', '150000000.00', '3000000.00', '189250000.00', '280000000.00', '280000000.00', '200000000.00', '2250000.00', '85000000.00', '2600000.00', '230000000.00', '680000000.00', '158000000.00', '230000000.00', '300000000.00', '200000000.00', '295000000.00', '250000000.00', '155000000.00', '143850000.00', '182000000.00', '3900000.00', '2200000.00', '91475000.00', '190000000.00', '2100000.00', '325000000.00', '118534000.00', '230000000.00', '3500000.00', '83688000.00', '320000000.00', '565000000.00', '162000000.00', '170000000.00', '265000000.00', '250000000.00', '120000000.00', '230000000.00', '88000000.00', '85000000.00', '209000000.00', '83000000.00', '161300000.00', '215000000.00', '120000000.00', '265000000.00', '167000000.00', '280000000.00', '70000000.00', '410000000.00', '215000000.00', '118000000.00', '179800000.00', '211000000.00', '131750000.00', '2400000.00', '319800000.00', '2400000.00', '140000000.00', '230000000.00', '250000000.00', '2100000.00', '137000000.00', '260000000.00', '178100000.00', '565000000.00', '160000000.00', '173000000.00', '240000000.00', '157000000.00', '176000000.00', '130000000.00', '118000000.00', '131964000.00', '85000000.00', '102268800.00', '92000000.00', '140000000.00', '148000000.00', '3200000.00', '160000000.00', '385000000.00', '140000000.00', '105000000.00', '2700000.00', '88000000.00', '129000000.00', '547950000.00', '250000000.00', '230000000.00', '138000000.00', '225000000.00', '230000000.00', '230000000.00', '230000000.00', '210000000.00', '189000000.00', '140000000.00', '328000000.00', '140000000.00', '220000000.00', '319800000.00', '85000000.00', '100000000.00', '170000000.00', '210000000.00', '2600000.00', '195000000.00', '165000000.00', '160000000.00', '195000000.00', '3800000.00', '250000000.00', '260000000.00', '230000000.00', '85000000.00', '2500000.00', '165000000.00', '86000000.00', '3900000.00', '210000000.00', '230000000.00', '434000000.00', '1600000.00', '1750000.00', '310000000.00', '165000000.00', '290000000.00', '85000000.00', '5000000.00', '380000000.00', '208000000.00', '325000000.00', '110000000.00', '40000000.00', '260000000.00', '207000000.00', '215000000.00', '450000000.00', '1600000.00', '150000000.00', '280000000.00', '220000000.00', '195975000.00', '190000000.00', '190000000.00', '297000000.00', '104100000.00', '110000000.00', '380000000.00', '270000000.00', '100000000.00', '88000000.00', '2400000.00', '2100000.00', '170000000.00', '116700000.00', '88000000.00', '155000000.00', '2400000.00', '2300000.00', '2600000.00', '120000000.00', '4000000.00', '235000000.00', '418000000.00', '125000000.00', '255000000.00', '290000000.00', '200000000.00', '233000000.00', '390000000.00', '190000000.00', '1280000000.00', '160050000.00', '285000000.00', '175000000.00', '137000000.00', '205000000.00', '126000000.00', '150000000.00', '800000000.00', '2000000.00', '160000000.00', '205000000.00', '137000000.00']

datas = ["5", "6" , "11", "1", "21", "5", "5", "5", "5", "1.00", "3.00", "5.00"]
# print([int(datas) for datas in datas])

print(int(str(datas)))

I have tried several methods, but I am looking for the most straight easy method.
I have been getting ValueError: invalid literal for int() with base 10: '' as an error whenever i wanted to use int() method, then i tried to use str() method where float() cant be used on strings again. So i am stuck.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Replace:

print(int(str(datas)))

With:

print(list(map(float,datas)))

Or if you want integers not float then:

print([int(float(data)) for data in datas])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading