Advertisement
maxim_shlyahtin

45353

May 19th, 2023
766
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. import pandas as pd
  2.  
  3. path1  = r'path to the csv table'
  4. path2  = r'path to the csv table'
  5.  
  6. #1
  7. ins_left = pd.read_csv(path1)
  8. ins_right = pd.read_csv(path2)
  9. print(ins_left.head())
  10.  
  11. #2
  12. print(ins_left.info(), ins_right.info(), sep='\n')
  13. print(ins_right.isnull.any(), ins_left.isnull.any(), sep='\n')
  14.  
  15. #3
  16. ins_right = ins_right.dropna()
  17. ins_left = ins_left.dropna()
  18.  
  19. #4
  20. ins_left = ins_left.drop_duplicates()
  21. ins_right = ins_right.drop_duplicates()
  22. df = pd.merge('column name from the first table', 'column name from the second table')
  23. print(df.info())
  24.  
  25. #5
  26. female = pd.DataFrame(ins_left[(15 <= ins_left.age) & (ins_left.age <= 75)])
  27. print(female.head(20))
  28.  
  29. #6
  30. df['cigs2'] = df['cigs2'].mask(df['cigs'] < 10, 1)
  31. df['cigs2'] = df['cigs2'].mask((df['cigs'] >= 10) & (df['cigs'] < 20), 2)
  32. df['cigs2'] = df['cigs2'].mask(df['cigs'] > 20, 3)
  33. print(df.loc[df['cigs2'] == 1, df['age'].mean()])
  34. print(df.loc[df['cigs2'] == 2, df['age'].mean()])
  35. print(df.loc[df['cigs2'] == 3, df['age'].mean()])
  36.  
  37. #8
  38. df1 = df[]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement