vmamontov

use_func_no_cicle

Apr 11th, 2022
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. pd = __import__('pandas')
  2. np = __import__('numpy')
  3.  
  4. df = pd.read_csv('https://vk.com/s/v1/doc/Q8dE2aqabEx6LLW_FVGZLwrYk0afhuc1JKCC5PfvrlxBgaKyrGI', names=['date', 'name', 'price'])
  5. # df.head()
  6. # date  name    price
  7. # 0 01.01.2020  сайт1   123000
  8. # 1 01.02.2020  сайт1   154000
  9. # 2 01.03.2020  сайт1   164000
  10. # 3 01.04.2020  сайт1   124000
  11. # 4 01.05.2020  сайт1   178000
  12.  
  13. def func(data):
  14.     res = np.nan
  15.     if data < 154000:
  16.         res = 'min'
  17.     if data > 154000 and data < 165000:
  18.         res = 'medium'
  19.     else:
  20.         res = 'high'
  21.     return res
  22.  
  23. df['res'] = df['price'].apply(func)
  24. df.head()
  25.  
  26.  
  27. # date  name    price   res
  28. # 0 01.01.2020  сайт1   123000  high
  29. # 1 01.02.2020  сайт1   154000  high
  30. # 2 01.03.2020  сайт1   164000  medium
  31. # 3 01.04.2020  сайт1   124000  high
  32. # 4 01.05.2020  сайт1   178000  high
Advertisement
Add Comment
Please, Sign In to add comment