+ 4

Pandas DF related problem - MISSING NUMBERS

''' In DS with Py, one of the end of module tasks, Given a list of numbers including some missing values, turn it into a pandas dataframe, impute the missing values with the mean, and finally return the dataframe. I have solved this challenge by not doing exactly the same as instructed and that's why even after solving the challenge, I am stuck here trying to find a way to do as said. ''' import numpy as np import pandas as pd lst = [float(x) if x != 'nan' else np.NaN for x in input().split()] df = pd.Series(lst) df = df.fillna(round(df.mean(),1)) print (df) Whenever I change that to df = pd.DataFrame(lst) Column name is automatically given as 0, which is expected but When I try to return that column like this Print (df.iloc[:,0] It prints everything fine but has one extra Name= 0 (for that column name) in the result and due to that, test doesn't pass. Can you suggest to get the expected output using pd.DataFrame??? Thanks in Advance!!!

11th Apr 2021, 4:23 AM
CHANDAN ROY
CHANDAN ROY - avatar
5 Answers
+ 3
import numpy as np import pandas as pd lst = [float(x) if x != 'nan' else np.NaN for x in input().split()] df = pd.Series(lst) df = df.fillna(round(df.mean(),1)) print (df)
19th Aug 2022, 10:12 AM
Muzaffar Bekturdiyev
0
Tony F ๐Ÿ™ thanks for your response. I had solved this challenge before writing this query. I just wanted to know if there is a solution to the questions I have raised?
21st May 2021, 7:17 AM
CHANDAN ROY
CHANDAN ROY - avatar
0
I think of myself as an ok Python and SQL developer, but I just can't grasp pandas. I have a simple task to build some gantt-type graphs from simple set of tasks with transfer speed and start/end dates, but I just can't wrap my mind around it. So, what's the best way to learn pandas? https://www.greatpeople-me.org/
7th Sep 2021, 5:11 AM
Lavonneb
0
import numpy as np import pandas as pd lst = [float(x) if x != 'nan' else np.NaN for x in input().split()] df = pd.Series(lst) df = df.fillna(round(df.mean(),1)) print (df) this code will more efficient ... and thanks a lot for giving hint...
3rd Sep 2022, 2:20 PM
Shaheen R Tirlapur
1
๐Ÿ…ฐ๐Ÿ…น (Challenge Accepted) Is there a way to remove that thing??
12th Apr 2021, 4:29 AM
CHANDAN ROY
CHANDAN ROY - avatar