Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 cannot convert the series to <class 'int'>
#1
Hello,

Can someone help me to solve this error?

df_sellout['DateTime'].head(10)
Output:
35 2018-08-10 36 2018-08-10 37 2018-08-10 81 2018-08-10 82 2018-08-10 130 2018-08-10 131 2018-08-10 132 2018-09-10 133 2018-08-10 180 2018-07-10 Name: DateTime, dtype: datetime64[ns]
def data_class(y):

    bins_name=[dt.datetime(day=20,month=1,year=y),dt.datetime(day=19,month=2,year=y),
               dt.datetime(day=20,month=3,year=y),dt.datetime(day=19,month=4,year=y),
               dt.datetime(day=20,month=5,year=y),dt.datetime(day=19,month=6,year=y),
               dt.datetime(day=20,month=7,year=y),dt.datetime(day=19,month=8,year=y),
               dt.datetime(day=20,month=9,year=y),dt.datetime(day=19,month=10,year=y),
               dt.datetime(day=20,month=11,year=y),dt.datetime(day=19,month=12,year=y),
               dt.datetime(day=20,month=1,year=y+1)
              ]
    return bins_name

labels_name=['jan','feb','mar','apr','mai','jun','jul','aug',
                'sep','oct','nov','dec']

df_sellout['data_periodo'] = pd.cut(df_sellout['DateTime'],bins=data_class(df_sellout['DateTime'].dt.year),labels=labels_name)
Error:
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-160-3247d6acec8d> in <module>() 14 'sep','oct','nov','dec'] 15 ---> 16 df_sellout['data_periodo'] = pd.cut(df_sellout['DateTime'],bins=data_class(df_sellout['DateTime'].dt.year),labels=labels_name) <ipython-input-160-3247d6acec8d> in data_class(y) 1 def data_class(y): 2 ----> 3 bins_name=[dt.datetime(day=20,month=1,year=y),dt.datetime(day=19,month=2,year=y), 4 dt.datetime(day=20,month=3,year=y),dt.datetime(day=19,month=4,year=y), 5 dt.datetime(day=20,month=5,year=y),dt.datetime(day=19,month=6,year=y), /anaconda3/lib/python3.6/site-packages/pandas/core/series.py in wrapper(self) 115 return converter(self.iloc[0]) 116 raise TypeError("cannot convert the series to " --> 117 "{0}".format(str(converter))) 118 119 return wrapper TypeError: cannot convert the series to <class 'int'>
Quote
#2
Anyone can help me?
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)