One line code using lambda Syntax Error

Hi everyone,

It is my first post in Jupyter community and if my question might not be posted here, my appologies for that.
Imagine you are execising on a data using your local jupyter notebook. The data looks like that:

import pandas as pd; import numpy as np

jhk = pd.DataFrame({'idx': np.arange(55),
                   'Value':['1,550.0',
 '1,739.6',
 '1,886.9',
 '1,880.2',
 '1,140.0',
 '1,212.5',
 '1,286.2',
 '1,315.1',
 '1,174.9',
 '1,169.3',
 '1,185.8',
 '1,188.6',
 '1,348.19',
 '1,393.72',
 '1,424.93',
 '1,425.89',
 '6,489.9',
 '6,733.2',
 '6,825.3',
 '6,814.3',
 '17,415.5',
 '19,226.2',
 '21,133.8',
 '21,724.0',
 '3,126.2',
 '3,252.0',
 '3,270.9',
 '3,264.9',
 '1,353.4',
 '1,281.8',
 '1,181.8',
 '1,160.2',
 '1,240.61',
 '1,322.87',
 '1,396.39',
 '1,417.17',
 '1,205.2',
 '1,451.9',
 '1,714.8',
 '1,746.0',
 '1,329.4',
 '1,449.5',
 '1,636.1',
 '1,693.0',
 '22,267.5',
 '24,671.1',
 '24,779.9',
 '24,475.8',
 '7,560.2',
 '8,272.4',
 '8,652.8',
 '8,749.2',
 '1,182.5',
 '1,283.0',
 '1,299.3']})

As you noticed, values of Value column are netiher integer nor float even if you try to convert them from string to float type. It is going to throw an error. Try.

You might convert jhk.Value column to its appropriate data type float in many ways, e.g.

ll = jhk.Value.to_list() 
cc = []
for i in ll:
    if len(i) > 6:
        ls = i.rsplit('.', 1)[0].replace(',', '.')
        cc.append(i)
        print(i)
    else:
        cc.append(i)

jhk.Values = cc 

As the code above is written in multiple lines, you would like to write it in a line like a pro :slight_smile:
E.g:

jhk.Value = jhk.apply(lambda k: i.rsplit('.', 1)[0].replace(',', '.') if len(i) >6 for i in k.Value.to_list())

However, this code has a syntax error. May I ask you what I am missing to have a syntax error and where?

In addition, what the Data experts do with such kind of data values?

Thanks in adavnce.

Kind regards,
Kanatbek-AKA