O2O-Coupon-Usage-Forecast icon indicating copy to clipboard operation
O2O-Coupon-Usage-Forecast copied to clipboard

在运行get_day_gap_before时出现了问题

Open tangxxx121 opened this issue 1 year ago • 1 comments

t7['day_gap_before'] = t7.date_received_date.apply(get_day_gap_before) Traceback (most recent call last):

File "C:\Users\TangX\AppData\Local\Temp\ipykernel_10460\2415590082.py", line 1, in <cell line: 1> t7['day_gap_before'] = t7.date_received_date.apply(get_day_gap_before)

File "F:\Anaconda_app\lib\site-packages\pandas\core\series.py", line 4433, in apply return SeriesApply(self, func, convert_dtype, args, kwargs).apply()

File "F:\Anaconda_app\lib\site-packages\pandas\core\apply.py", line 1082, in apply return self.apply_standard()

File "F:\Anaconda_app\lib\site-packages\pandas\core\apply.py", line 1137, in apply_standard mapped = lib.map_infer(

File "pandas_libs\lib.pyx", line 2870, in pandas._libs.lib.map_infer

File "C:\Users\TangX\AppData\Local\Temp\ipykernel_10460\2229747806.py", line 6, in get_day_gap_before this_gap = (date(int(date_received[0:4]),int(date_received[4:6]),int(date_received[6:8]))-date(int(d[0:4]),int(d[4:6]),int(d[6:8]))).days

ValueError: invalid literal for int() with base 10: 'Date'

tangxxx121 avatar Aug 12 '22 02:08 tangxxx121

找到问题了,在读取文件时有header=None,并且后面有重新设置了列名 off_train.columns= ['user_id','merchant_id','coupon_id','discount_rate','distance','date_received','date']。导致原来的列名现在变成了第0行的数据。这样的问题大家怎么解决的了?

tangxxx121 avatar Aug 12 '22 03:08 tangxxx121