+ 2

Missing numbers DS python

Where is the problem with this solution? import numpy as np import pandas as pd lst = [float(x) if x != 'nan' else np.NaN for x in input().split()] n = pd.DataFrame(lst) n.fillna(round(n.mean(), 1), inplace = True) print(n[0])

27th Mar 2021, 9:47 PM
Ahmed Azami Hassani
Ahmed Azami Hassani - avatar
3 Respostas
+ 5
I am not sure, if this is the exact problem (did not run your code), but I used a pd.Series instead of a pd.DataFrame (the output layout slightly diverges) https://www.sololearn.com/discuss/2630791/?ref=app
28th Mar 2021, 8:18 AM
Lisa
Lisa - avatar
+ 3
The trick is turning the output into a string. Below worked for me. import numpy as np import pandas as pd lst = [float(x) if x != 'nan' else np.NaN for x in input().split()] df = pd.DataFrame(lst) df = df.fillna(df.mean().round(1)) print(df[0].to_string()) print('dtype: '+str(df[0].dtypes))
1st Apr 2021, 9:09 PM
Timur Ganiev
Timur Ganiev - avatar
0
import numpy as np import pandas as pd lst = [float(x) if x != 'nan' else np.NaN for x in input().split()] ps = pd.Series(lst) ps = ps.fillna(ps.mean()) print(ps.round(1))
9th Oct 2022, 10:01 PM
Andreas Paar
Andreas Paar - avatar