Support
Quality
Security
License
Reuse
kandi has reviewed borel and discovered the below as its top functions. This is intended to give you an instant insight into borel implemented functionality, and help decide if they suit your requirements.
Get all kandi verified functions for this library.
Get all kandi verified functions for this library.
Enables regular set operations on any ordered class
See all related Code Snippets
QUESTION
Convert only the numeric elements of pd.series to float
Asked 2020-Jul-02 at 14:58nome
Douglas Friedrich custo zero
Ernando custo zero
Lucas Fonseca custo zero
Éverson NA
Juninho Capixaba desconhecido
Zeca desconhecido
Nino Paraíba custo zero
Douglas Borel NA
Elton custo zero
Ronaldo custo zero
Jádson desconhecido
Rodriguinho custo zero
Marco Antônio 120 mil €
Clayson 880 mil €
Rossi custo zero
Gilberto custo zero
Saldanha NA
Anderson NA
Juninho 1.30 milhões €
Wanderson 400 mil €
Ignácio desconhecido
Giovanni custo zero
João Pedro desconhecido
Matheus Silva custo zero
Gregore 235 mil €
Flávio desconhecido
Yuri custo zero
Saldanha NA
Danielzinho custo zero
Alesson desconhecido
Élber 130 mil €
Gustavo NA
Fernandão 1.06 milhões €
Name: preco_pago, dtype: object
Is there anyway that I can convert only the numeric element of this series to float(ex: 1.30 milhões €
) and leave the rest as it is ? I also would like to convert thousands to 1000 and millions to millions 1000000. This is what I actually want : 1.30 milhões €
to 1300000
ANSWER
Answered 2020-Jul-02 at 14:52If I understood correctly, you have a pandas Series with strings (i.e. your first element is the string 'Douglas Friedrich custo zero'
.
You'll have to create your own function to parse each string, for example:
def convert_to_number(s):
n = s.split(' ').strip() # work with the right-hand portion only
if 'milhões' in n:
return 1e6 * float(n.split()[0])
if 'mil' in n:
return 1e3 * float(n.split()[0])
if 'zero' in n:
return 0
return np.nan
Then simply apply this function to your pandas series:
new_series = series.apply(convert_to_number)
Of course, you may need to modify the function depending on your needs, or adapt it to any edge cases that may come along.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Find more information at:
Save this library and start creating your kit
See Similar Libraries in
Save this library and start creating your kit
Open Weaver – Develop Applications Faster with Open Source