Python Forum
cannot convert the series to <class 'int'>
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'>
Reply
#2
Anyone can help me?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I convert time-series data in rows into column srvmig 0 2,035 Apr-11-2020, 05:40 AM
Last Post: srvmig

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020