Home > other >  Percentage of Python pandas package to CSV is converted to a decimal (not by a string to a floating-
Percentage of Python pandas package to CSV is converted to a decimal (not by a string to a floating-

Time:12-17

First attempt:
 Players_data [' 2017 _win]=Players_data [' 2017 _win] STR. Replace (' % ', ', the regex=False) 
For I in range (len (Players_data [' 2017 _win '])) :
Float (Players_data [' 2017 _win] [I])

Error: ValueError: could not convert a string to float: "'

A second attempt:
 Players_data [' 2017 _win]=Players_data [' 2017 _win]. Apply (lambda x: np. Nan if x (' - ') in the else x] [: - 1). The astype (float)/100 


Error: still ValueError: could not convert a string to float: "'

Why want to ask: "why there is no any content no Spaces within or not by a string to a floating-point number??
Thank you!

CodePudding user response:

The third attempt:
 def convert_percent (value) : 
New_value=https://bbs.csdn.net/topics/value.replace (' % ', ')
New_value=(https://bbs.csdn.net/topics/new_value.strip)
Return a float (new_value)/100
Players_data [' 2017 _win]. Apply (convert_percent)


An error is still the same way...

CodePudding user response:

Settled, check the source file is found in front of the missing value to empty, cause there is an index
  • Related