ValueError Traceback (most recent call last) Cell In[1], line 33 31 # 将展会时间转换为日期范围 32 df[‘开始日期’] = df[‘展会时间’].apply(lambda x: datetime.strptime(x.split(‘-’)[0], ‘%Y.%m.%d’)) —> 33 df[‘结束日期’] = df[‘展会时间’].apply(lambda x: datetime.strptime(x.split(‘-’)[1], ‘%Y.%m.%d’)) 35 # 计算展会持续天数 36 df[‘持续天数’] = (df[‘结束日期’] - df[‘开始日期’]).dt.days
File /usr/local/lib/python3.10/site-packages/pandas/core/series.py:4924, in Series.apply(self, func, convert_dtype, args, by_row, **kwargs) 4789 def apply( 4790 self, 4791 func: AggFuncType, (…) 4796 **kwargs, 4797 ) -> DataFrame | Series: 4798 “”" 4799 Invoke function on values of Series. 4800 (…) 4915 dtype: float64 4916 “”" 4917 return SeriesApply( 4918 self, 4919 func, 4920 convert_dtype=convert_dtype, 4921 by_row=by_row, 4922 args=args, 4923 kwargs=kwargs, -> 4924 ).apply()
File /usr/local/lib/python3.10/site-packages/pandas/core/apply.py:1427, in SeriesApply.apply(self) 1424 return self.apply_compat() 1426 # self.func is Callable -> 1427 return self.apply_standard()
File /usr/local/lib/python3.10/site-packages/pandas/core/apply.py:1507, in SeriesApply.apply_standard(self)
1501 # row-wise access
1502 # apply doesn’t have a na_action
keyword and for backward compat reasons
1503 # we need to give na_action="ignore"
for categorical data.
1504 # TODO: remove the na_action="ignore"
when that default has been changed in
1505 # Categorical (GH51645).
1506 action = “ignore” if isinstance(obj.dtype, CategoricalDtype) else None
-> 1507 mapped = obj._map_values(
1508 mapper=curried, na_action=action, convert=self.convert_dtype
1509 )
1511 if len(mapped) and isinstance(mapped[0], ABCSeries):
1512 # GH#43986 Need to do list(mapped) in order to get treated as nested
1513 # See also GH#25959 regarding EA support
1514 return obj._constructor_expanddim(list(mapped), index=obj.index)
File /usr/local/lib/python3.10/site-packages/pandas/core/base.py:921, in IndexOpsMixin._map_values(self, mapper, na_action, convert) 918 if isinstance(arr, ExtensionArray): 919 return arr.map(mapper, na_action=na_action) –> 921 return algorithms.map_array(arr, mapper, na_action=na_action, convert=convert)
File /usr/local/lib/python3.10/site-packages/pandas/core/algorithms.py:1743, in map_array(arr, mapper, na_action, convert) 1741 values = arr.astype(object, copy=False) 1742 if na_action is None: -> 1743 return lib.map_infer(values, mapper, convert=convert) 1744 else: 1745 return lib.map_infer_mask( 1746 values, mapper, mask=isna(values).view(np.uint8), convert=convert 1747 )
File lib.pyx:2972, in pandas._libs.lib.map_infer()
Cell In[1], line 33, in <lambda>(x) 31 # 将展会时间转换为日期范围 32 df[‘开始日期’] = df[‘展会时间’].apply(lambda x: datetime.strptime(x.split(‘-’)[0], ‘%Y.%m.%d’)) —> 33 df[‘结束日期’] = df[‘展会时间’].apply(lambda x: datetime.strptime(x.split(‘-’)[1], ‘%Y.%m.%d’)) 35 # 计算展会持续天数 36 df[‘持续天数’] = (df[‘结束日期’] - df[‘开始日期’]).dt.days
File /usr/local/lib/python3.10/_strptime.py:568, in _strptime_datetime(cls, data_string, format) 565 def _strptime_datetime(cls, data_string, format=“%a %b %d %H:%M:%S %Y”): 566 “”“Return a class cls instance based on the input string and the 567 format string.”“” –> 568 tt, fraction, gmtoff_fraction = _strptime(data_string, format) 569 tzname, gmtoff = tt[-2:] 570 args = tt[:6] + (fraction,)
File /usr/local/lib/python3.10/_strptime.py:349, in _strptime(data_string, format) 347 found = format_regex.match(data_string) 348 if not found: –> 349 raise ValueError(“time data %r does not match format %r” % 350 (data_string, format)) 351 if len(data_string) != found.end(): 352 raise ValueError(“unconverted data remains: %s” % 353 data_string[found.end():])
ValueError: time data ‘6’ does not match format ‘%Y.%m.%d’