Q. Given a data-frame Sales that store sales records of a company of past few years. But the data-frame contains some missing data.
| Item Type | Sales Channel | Order Date | Order ID | Total Revenue | Total Cost | Total Profit | |
|---|---|---|---|---|---|---|---|
| 0 | Cosmetics | Online | 5/22/2017 | 8985.0 | 793518.00 | 477943.95 | 315574.85 | 
| 1 | Cereal | Online | 5/20/2017 | 5559.0 | 1780539.20 | 1013704.16. | 766835.84 | 
| 2 | Personal Care | Offline | NaN | NaN | NaN | NaN | NaN | 
| 3 | Personal Care | Online | 3/11/2017 | 6992.0 | 246415.95 | 170860.05 | 75555.90 | 
| 4 | Snacks | Online | 2/25/2017 | 7562.0 | 1117953.66 | 713942.88 | 404010.78 | 
| 5 | Household | Offline | 2/8/2017 | 52284.0 | 5997054.98 | 4509793.96 | 1487261.82 | 
| 6 | Meat | Online | NaN | NaN | NaN | NaN | NaN | 
| 7 | Clothes | Online | 1/13/2017 | 1873.0 | 902980.64 | 296145.92 | 606834.72 | 
| 8 | Cosmetics | Online | 12/31/2016 | 331438481.0 | 3876652.40 | 2334947.11 | 1541705.29 | 
| 9 | Office Supplies | Offline | NaN | NaN | NaN | NaN | NaN | 
| 10 | Cosmetics | Offline | 11/19/2016 | 419123971.0 | 3039414.40 | 1830670.16 | 1208744.24 | 
| 11 | Cosmetics | Online | 11/15/2016 | 286959302.0 | 2836990.80 | 1708748.37 | 1128242.43 | 
| 12 | Beverages | Offline | NaN | NaN | NaN | NaN | NaN | 
| 13 | Clothes | Offline | 7/25/2016 | 807025039.0 | 600821.44 | 197048.32 | 403773.12 | 
| 14 | Snacks | Online | 6/30/2016 | 795490682.0 | 339490.50 | 216804.00 | 122686.50 | 
Write a script that does the following:-
(i) Lists the presence of missing data in whole data-frame.
(ii) Fills the missing values with 999.
(iii) Print the data-frame after filling missing value.
Answer :-
import pandas as pd
import numpy as np.
# creation or loading of dataframe Sales
# presence of missing data element wise
print("Missing data element wise")
print((Sales.isnull() ) )
Sales Sales.fillna (999)
print("After filling missing values with 999, the dataframe is like:")
print (Sales)
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )