+ 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])
3 Answers
+ 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
+ 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))
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))