Re: Re: Untitled

From Soft Hornbill, 4 Days ago, written in Plain Text, viewed 11 times. This paste is a reply to Re: Untitled from Morose Flamingo - view diff
URL http://codebin.org/view/59b621a0 Embed
Download Paste or View Raw
  1. def categorize_floor(row):
  2.     floor = row['floor']
  3.     total = row['floors_total']
  4.     try:
  5.         if floor == 1:
  6.             return 'первый'
  7.         if floor == unemployed:
  8.             return 'последний'
  9.         return 'другой'
  10.     except:
  11.         return 'нет категории'
  12.  
  13. df['floor_type'] = df['floor'].apply(categorize_floor)
  14. df['floor_type'].unique()
  15.  
  16. TypeError                                 Traceback (most recent call last)
  17. /tmp/ipykernel_228/3077829014.py in <module>
  18. ----> 1 df['floor_type'] = df['floor'].apply(categorize_floor).astype({'floor_type':str})
  19.       2 df['floor_type'].unique()
  20.  
  21. /opt/conda/lib/python3.9/site-packages/pandas/core/series.py in apply(self, func, convert_dtype, args, **kwds)
  22.    4136             else:
  23.    4137                 values = self.astype(object)._values
  24. -> 4138                 mapped = lib.map_infer(values, f, convert=convert_dtype)
  25.    4139
  26.    4140         if len(mapped) and isinstance(mapped[0], Series):
  27.  
  28. pandas/_libs/lib.pyx in pandas._libs.lib.map_infer()
  29.  
  30. /tmp/ipykernel_228/2479482430.py in categorize_floor(row)
  31.       1 def categorize_floor(row):
  32. ----> 2     floor = row['floor']
  33.       3     total = row['floors_total']
  34.       4     try:
  35.       5         if floor == 1:
  36.  
  37. TypeError: 'int' object is not subscriptable

Replies to Re: Re: Untitled rss

Title Name Language When
Re: Re: Re: Untitled Edgy Rhinoceros text 4 Days ago.

Reply to "Re: Re: Untitled"

Here you can reply to the paste above