+ 2

Module 3 Quiz - Data Science

My problem is in the Quiz of module 3, from Data Science course. It could be said that I already have solved this problem, but at the end of my output there is something that I do not want, I mean, IDK how to quit that part; what I'm talking about is this: Name: 0, dtype: float64 I would like to have just the 'dtype', so what could I do, my code is the following if you want to check and tell me if something I put is causing this: import pandas as pd import numpy as np lst = [float(x) if x != 'nan' else 'NaN' for x in input().split()] new_lst = [] for j in lst: if j == 'NaN': continue else: new_lst.append(j) mean = np.mean(new_lst) for i in lst: if i == 'NaN': index = lst.index(i) lst.remove(i) lst.insert(index, mean.round(1)) else: continue lst = pd.DataFrame(lst) print(lst[0])

14th Apr 2021, 1:18 AM
Bry4n
Bry4n - avatar
8 Answers
+ 2
Think more about Pandas Series, because the output, it looks like a series, your output is a dataframe... something like this? https://code.sololearn.com/cfag9BiW4MO5/?ref=app
14th Apr 2021, 1:36 AM
Steven M
Steven M - avatar
+ 3
Sometimes you don't need to drop the whole row especially when you are preparing your data for a classifier.. fillna() fills the position of NaN values with the given argument.
14th Apr 2021, 3:46 AM
Ahmed Yasser
Ahmed Yasser - avatar
+ 3
Oh that's fairly handy, thanks Ahmed Yasser :D
14th Apr 2021, 4:25 AM
Bry4n
Bry4n - avatar
+ 2
( ‱_‱)>⌐■-■ Dude I forgot about series, you cannot be more right, thanks a lot you solve my problem :D
14th Apr 2021, 3:07 AM
Bry4n
Bry4n - avatar
+ 2
import numpy as np r = int(input()) lst = [float(x) for x in input().split()] arr_ABD = np.array(lst) arr_ABD = arr_ABD.reshape(r,int(len(lst)/r)) print(arr_ABD.round(2))
14th Sep 2021, 7:45 AM
Brigido bergado jr
Brigido bergado jr - avatar
+ 1
Just a question, how does the function fillna() works?? I mean when I have to use it, I cannot entirely get it.
14th Apr 2021, 3:10 AM
Bry4n
Bry4n - avatar
+ 1
Copy this code answer and like and check thank-you
14th Sep 2021, 7:46 AM
Brigido bergado jr
Brigido bergado jr - avatar
0
I'm doing the same exercise in Sololearn (#3, missing numbers) and it actually states in the task that you have to put the data in a pandas DataFrame. Then you have to make sure that the missing numbers (NaN) will become replaced by the mean of the rest of the numbers. I did all that with the following code, but now I am frustrated by the same problem as mentioned above... the last line contains "Name: 0, dtype: float64" and according to Sololearn that's not correct, it should just say" dtype: float 64" as last line. Any suggestions? This is the code I use: mport numpy as np import pandas as pd lst=[float(x) if x!='nan' else np.NaN for x in input().split()] for i in range(0,len(lst)): if np.isnan(lst[i])==True: lst[i]=round(np.nanmean(lst),1) df=pd.DataFrame([lst]) print(df.loc[0,0:6])
1st Jul 2021, 7:01 PM
Eric
Eric - avatar