Home > Mobile >  Turn dataframe column into list of integers / floats (not string). tolist() not working
Turn dataframe column into list of integers / floats (not string). tolist() not working

Time:12-05

So I have dataframe with a column names "expense" that has floating numbers in them like this-

expense

20.00

15.00

3.00

6.00

3.00

2.5
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

I wanted to turn that into a list. I used temp['expense'].tolist() and I got this-

['$20.00', '$15.00', '$3.00', '$6.00', '$3.00', '$2.50']
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

which is a list of strings. I want the floating numbers to stay float so I can do math on them later. What can I do to achieve that?

Kind of new to it. So thanks for any help.

CodePudding user response:

Try:

temp['expense'].str[1:].astype(float).tolist()

If every entry in temp['expense'] has a dollar sign, then it should work.

  • Related