+ 1
How lst = [float(x) if x != 'nan' else np.NaN for x in input().split()] works
Hello, i wanna ask about something I wanna know how this code works, it actually has been used for lots of question in datascience project in sololearn lst = [float(x) if x != 'nan' else np.NaN for x in input().split()] One of the full code example down here :. Import numpy as np Import pandas as pd lst = [float(x) if x != 'nan' else np.NaN for x in input().split()] lst_df = pd.Series(lst) Sylv = lst_df.fillna(lst_df.mean()).round(1) print(Sylv)
5 Réponses
+ 1
lst = [float(x) if x != 'nan' else np.NaN for x in input().split()]
Its generator
And equal this:
lst =[]
For x in input().split():
if x =! 'nan':
lst.append(float(x))
else:
lst.append(np.NaN)
+ 2
list comprehension:
https://www.sololearn.com/learning/2454/
cant post a link that works so look for it in python tutorial
+ 1
input().split() its splitted into list input from user (by spaces in default)
+ 1
if on input u have "2 1 3 nan" on output u will have [2.0, 1.0, 3.0, NaN]
0
Илья Мирошник Thank you xD, it helps lot