I have a column in Pandas.DataFrame where every row of this column is the list of numbers. But these number is typed as string
The column name is allmz, the dataframe is exp_df
print exp_df.iloc[:3]['allmz']
>2129 [445.120788574, 355.067465091, 355.069260997, ...
>2130 [445.120758057, 355.06748396, 355.069279865, 3...
>2131 [445.120880127, 355.067417985, 355.06921389, 3...
>Name: allmz, dtype: object
I tried to convert each number by iteritemsbut the type is still str. Although I assign mzz = float(mzz).
for ind, mzlist in exp_df['allmz'].iteritems():
for mzz in mzlist:
mzz = float(mzz)
print type(exp_df.iloc[0]['allmz'][0])
><type 'str'>
Each list comes from exp_df['allmz'] = exp_df['allmz'].apply(lambda x: x.split(" ")) so I tried to do
exp_df[each] = exp_df[each].apply(lambda x: float(y) for y in x.split(" "))
But I guess lambda is not applicable with for loop. How I can access and convert string in list in each row of Pandas.DataFrame?
mzz = float(mzz)does not do anything to the series. It only changes the object thatmzzreferences. Variables != Objects.