Question

In: Computer Science

Create a pandas dataframe and then impute missing values . data = { 'test' : [1,2,3,4,10,15]...

Create a pandas dataframe and then impute missing values .

data = { 'test' : [1,2,3,4,10,15]

'missing' : [1,2,4,None,5,7] }

replace the missing values in the missing table column with mean values using mean imputation

============

i am trying like this but i am not getting correct output and getting confused please explain with proper output and explanation

import pandas as pd

pd.DataFrame(data)

temp = pd.DataFrame(data).fillna(np.mean())

temp ['missing'] . fillna(temp['missing'].mean())

================

i am too much confused please write proper program with complete output

Solutions

Expert Solution

you missed iplace=True inside fillna method

data = { 'test' : [1,2,3,4,10,15],
'missing' : [1,2,4,None,5,7] }
import pandas as pd
import numpy as np
pd.DataFrame(data)
temp = pd.DataFrame(data)
print(temp)
temp ['missing'].fillna(temp['missing'].mean(),inplace=True)
print("\nAfter replacing none values to mean value")
print(temp)

when more columns contains None then

data = { 'test' : [1,2,None,4,10,15],
'missing' : [1,2,4,None,5,7] }
import pandas as pd
import numpy as np
pd.DataFrame(data)
temp = pd.DataFrame(data)
print(temp)
#temp ['missing'].fillna(temp['missing'].mean(),inplace=True)
temp.fillna(temp.mean(),inplace=True)
print("\nAfter replacing none values to mean value")
print(temp)


Related Solutions

#########################PANDAS LANGUAGE################## #########################MATPLOT LIB######################### # read movie.csv into a DataFrame called 'movie' # describe the dataframe...
#########################PANDAS LANGUAGE################## #########################MATPLOT LIB######################### # read movie.csv into a DataFrame called 'movie' # describe the dataframe #rename the column Runtime (Minutes) with Runtime_Minutes, and Revenue (Millions) with Revenue_Millions # show if any column has null value # count total number of null vlaues in the dataframe # print those rows which has null values # fill null values, #if column is numerical than fill with means (if there is no numerical missing value in #data frame then don't code in...
How do I select every row in pandas dataframe?
How do I select every row in pandas dataframe?
Assume you have the Pandas DataFrame data, with the following contents: our_columns_name column_A column_B column_C column_D...
Assume you have the Pandas DataFrame data, with the following contents: our_columns_name column_A column_B column_C column_D column_E our_index_name                                                    row_name_0               9        93        71    Hello       102 row_name_1              28        64        37       my        92 row_name_2              13        91        93     name       104 row_name_3              45        29        54       is        74 row_name_4               0        36        31    Jason        36 Each column has a dtype (data type). Which of the following could be set of dtypes for this DataFrame? Hint 1: None of the numeric values shows a decimal point. (A float...
######################LANGUAGE PANDAS#################### #####################MATPLOTLIB########################### ######################################################### # read ufo.csv into a DataFrame called 'ufo' # print the head...
######################LANGUAGE PANDAS#################### #####################MATPLOTLIB########################### ######################################################### # read ufo.csv into a DataFrame called 'ufo' # print the head and the tail # examine the default index, data types, and shape of ufo dataframe # count the number of missing values in each column # count total number of null vlaues in the dataframe # print those rows which has null values # fill null values, #if any column is numerical has null value than fill this column with mean of that column...
######################LANGUAGE PANDAS#################### #####################MATPLOTLIB########################### ######################################################### # read ufo.csv into a DataFrame called 'ufo' # print the head...
######################LANGUAGE PANDAS#################### #####################MATPLOTLIB########################### ######################################################### # read ufo.csv into a DataFrame called 'ufo' # print the head and the tail # examine the default index, data types, and shape of ufo dataframe # count the number of missing values in each column # count total number of null vlaues in the dataframe # print those rows which has null values # fill null values, #if any column is numerical has null value than fill this column with mean of that column...
Using pandas Read in the movies.csv into a dataframe named movies, display the first 5 rows...
Using pandas Read in the movies.csv into a dataframe named movies, display the first 5 rows and answer * Use the filter method to select the column names that contain the exact string facebook [ ] * Use the count method to find the number of non-missing values for each column. [ ] * Display the count of missing values for each column
Analyze used car inventory dataset using Python's pandas library - using DataFrame data structure¶ Dataset: UsedCarInventory_Assignment1.txt...
Analyze used car inventory dataset using Python's pandas library - using DataFrame data structure¶ Dataset: UsedCarInventory_Assignment1.txt (available on Canvas) This dataset shows used cars available for sale at a dealership. Each row represents a car record and columns tell information about each car. The first row in the dataset contains column headers. You must use Pandas to complete all 10 tasks.
find the values missing from the table below, and then create two (2) graphs for an...
find the values missing from the table below, and then create two (2) graphs for an individual price-taking firm that produces t-shirts, utilizing both the Marginal Revenue/Marginal Cost approach and the Total Revenue/Total Cost approach. The graphs should depict the effect of a change in consumer demographics that increases demand for hairnets and increases the market price to $24. 1. Create a graph (Graph 1) showing the starting conditions using the Marginal Revenue/Marginal Cost approach; correctly label all axes, curves,...
find the values missing from the table below, and then create two (2) graphs for an...
find the values missing from the table below, and then create two (2) graphs for an individual price-taking firm that produces t-shirts, utilizing both the Marginal Revenue/Marginal Cost approach and the Total Revenue/Total Cost approach. The graphs should depict the effect of a change in consumer demographics that increases demand for hairnets and increases the market price to $24. 1. Create a graph (Graph 1) showing the starting conditions using the Marginal Revenue/Marginal Cost approach; correctly label all axes, curves,...
Pandas exercises: 1. Write a python program using Pandas to create and display a one-dimensional array-like...
Pandas exercises: 1. Write a python program using Pandas to create and display a one-dimensional array-like object containing an array of data. 2. Write a python program using Pandas to convert a Panda module Series to Python list and print it's type. (Hint: use ds.tolist() to convert the pandas series ds to a list) 3. Create a pandas dataframe called **my_df** with index as integer numbers between 0 to 10, first column (titled "rnd_int") as 10 integer random numbers between...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT