0
How to use suggested code in project "Missing Numbers"?
# Anybody knows how to write thу code project "Missing Numbers" # in the module "Data Visualization" of # the course "Data Science" usign the string, suggested in the task ? #lst = [round(float(x), 1) if x != 'nan' else np.NaN for x in input().split()]
5 ответов
+ 6
Dmitry Arkhangelsky ,
can you please show us the complete code?
also you should read the task description. elements that contain 'nan' has to be replaced by the mean value of the complete data range. you are trying to use round() in the comprehension.
the compression also uses 'np.' which indicates that numpy is used.
thanks!
+ 6
Dmitry Arkhangelsky ,
i have used your code as it is, and ran it in the code coach exercice. it has passed all test cases, so it is working correctly.
what kind of issue did you get?
any error messages?
+ 1
# Thank You for such quick an answer, highly respected Lothar
# That's my code
import pandas as pd
lst = [float(x) if x != 'nan' else 'nan' for x in input().split()]
# I don't know how to make a copy of 'list' data in a memory and I needed to
# change one list and to preserve it's original copy
lstorig = tuple(lst)
lstorig = [i for i in lstorig]
cnt = 0
for i in lst:
if i == 'nan':
del lst[cnt]
cnt += 1
ser = pd.Series(lst)
n_repl = ser.mean()
print()
cnt = 0
for i in lstorig:
if i == 'nan':
lstorig[cnt] = n_repl
cnt += 1
ser = pd.Series(lstorig).round(1)
print(ser)
0
Thank You for sincere question Lothar!
I'm really glad to meet your attention...
My issue is - how to write the code
solving this problem
Sample Input
3 4 5 3 4 4 nan
Sample Output
0 3.0
1 4.0
2 5.0
3 3.0
4 4.0
5 4.0
6 3.8
dtype: float64
Explanation
The mean of 3, 4, 5, 3, 4, and 4 is 3.8, so we replace the missing value with the mean.
using this fragment -
lst = [round(float(x), 1) if x != 'nan' else np.NaN for x in input().split()]
0
Hii