Home > other >  The novice consult problem,
The novice consult problem,

Time:10-23

Dataframe column is' - 'data, has written the following code, want to change to float, but did not succeed, give advice or comments please god?

Df2 [' icratio]=df2 [' icratio] STR. Replace (' - ', '). Astype (np) float64)

System tip: could not convert a string to float:

CodePudding user response:

Tip is not converts a string to a floating-point type data, you can add a float switch in front, such as float (STR)

If the answer to help you, also please give the points,,,

CodePudding user response:

Whether need to put the string into a number first, and eval is similar to that role, I don't know understand right,

CodePudding user response:

reference 1st floor xiguayihao response:
prompt will not be able to type converts a string to a floating-point data, you can add a float switch in front, such as float (STR)

If the answer to help you, also please give the points,,,


Can you specifically about how to write?