Advertisement
ShrekOP

Assg24

Dec 14th, 2022
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import pandas as pd
  2. import numpy as np
  3.  
  4. df = pd.read_csv('data.csv')
  5. df
  6.  
  7. count_unique = df['bedrooms'].nunique() # Apply unique function
  8. print(count_unique) # Print count of unique values
  9.  
  10. count_unique = df['date'].nunique() # Apply unique function
  11. print(count_unique) # Print count of unique values
  12.  
  13. df.columns
  14.  
  15. # foematting dataset
  16. # Round off the column values to two decimal places in python pandas
  17. pd.options.display.float_format = '{:.2f}'.format
  18. print(df)
  19.  
  20. df['bedrooms']=df['bedrooms'].astype(str) #changing the data type of the bedrooms columns to string
  21. after = df.dtypes
  22. after
  23.  
  24. # identifying the missing values
  25. df.isnull().sum()
  26.  
  27. # filling the missing value
  28. replace_median = df['floors'].median()
  29. print(replace_median)
  30. print(df['floors'].fillna(replace_median, inplace=True))
  31.  
  32. # filling the missing value
  33. replace_mode = df['bedrooms'].mode()
  34. print(replace_mode)
  35. print(df['bedrooms'].fillna(replace_mode, inplace=True))
  36.  
  37. empty_rows= df[df['date'].isna()]
  38. empty_rows
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement