Did anyone do DS with Python the Missing Numbers assignment | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Did anyone do DS with Python the Missing Numbers assignment

Did someone did 3rd challenge from DS with python course? Mine always causes error. Here’s my code: import numpy as np import pandas lst = [float(x) if x != 'nan' else np.NaN for x in input().split()] from numpy import nan lst.fillna(lst.mean(), inplace=True) print(lst.isnull().sum()) DM please to explain!

18th Dec 2020, 8:52 AM
BatOchir Artur
BatOchir Artur - avatar
7 Answers
+ 2
lst is a list. I think it should be a pandas dataframe.
18th Dec 2020, 1:47 PM
Lisa
Lisa - avatar
+ 1
...series....and suddenly it is so easy. Thank you, Lisa! import numpy as np import pandas as pd lst = [float(x) if x != 'nan' else np.NaN for x in input().split()] ser = pd.Series(lst) mean= round(ser.mean(),1) ser = ser.where(ser.notna(),mean) print(ser)
6th Jan 2021, 9:55 AM
Trochoide
0
I have the same problem. The codes calculates the values correct, but when I print it, the result is correct, but the output ist missing the "dtype: float64" part. Adding a print(df.dtypes) doesn't work either, because the output states dtype object....
5th Jan 2021, 11:28 AM
Trochoide
0
Trochoide What type does your result have?
5th Jan 2021, 11:59 AM
Lisa
Lisa - avatar
0
Lisa I cannot copy paste the result, nor can I Post a Screenshot (or can I?), so I am typing the output 0 3.0 .... .... .... 6 3.8 floating64 dtype: object code: df=pd.DataFrame(lst, columns=[""]) print(df) print(df.dtypes)
6th Jan 2021, 7:42 AM
Trochoide
0
Trochoide You should be able to copy your code. Then you could save it in playground and link it. I looked it up how I solved it: I converted lst to a pandas series, replaced the nan and only printed the series in the end (it was float64)
6th Jan 2021, 9:06 AM
Lisa
Lisa - avatar
0
import numpy as np import pandas as pd lst = [float(x) if x != 'nan' else np.NaN for x in input().split()] ser=pd.Series(lst) mean_val = round(ser.mean(),1) ser1=ser.fillna(value=mean_val) print(ser1)
8th May 2021, 3:43 PM
Apoorva Datir
Apoorva Datir - avatar