Pandas DF related problem - MISSING NUMBERS | Sololearn: Learn to code for FREE!

+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!!!

4/11/2021 4:23:08 AM

CHANDAN ROY

5 Answers

New Answer

0

🅰🅹 (Challenge Accepted) Is there a way to remove that thing??

0

Use a Series instead of a DataFrame. A Series will print out in exactly the right format.

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?

0

Ah, I see. One user managed to get the correct output format 'by hand' with the code below. But really, it's just a badly written project/challenge that SoloLearn need to fix! Code from @Timur Ganiev: 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

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/