unhashable 类型:在 Pandas 中将 Object 转换为 datetime 时的“numpy.ndarray”

时间:2021-04-07 09:28:08

标签: python pandas string datetime

每当我尝试将列转换为 DateTime 格式时,我都会收到此错误。我的列是字符串格式,我试过在网上查找,但找不到任何可以帮助我解决此问题的内容。

    ---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-87-9a285deef407> in <module>
----> 1 pd.to_datetime(bookings_ship_time['purchase_order_requested_cargo_ready_date'], infer_datetime_format=True)
      2 
      3 

c:\users\marcus\appdata\local\programs\python\python38-32\lib\site-packages\pandas\core\tools\datetimes.py in to_datetime(arg, errors, dayfirst, yearfirst, utc, format, exact, unit, infer_datetime_format, origin, cache)
    799                 result = result.tz_localize(tz)
    800     elif isinstance(arg, ABCSeries):
--> 801         cache_array = _maybe_cache(arg, format, cache, convert_listlike)
    802         if not cache_array.empty:
    803             result = arg.map(cache_array)

c:\users\marcus\appdata\local\programs\python\python38-32\lib\site-packages\pandas\core\tools\datetimes.py in _maybe_cache(arg, format, cache, convert_listlike)
    171     if cache:
    172         # Perform a quicker unique check
--> 173         if not should_cache(arg):
    174             return cache_array
    175 

c:\users\marcus\appdata\local\programs\python\python38-32\lib\site-packages\pandas\core\tools\datetimes.py in should_cache(arg, unique_share, check_count)
    135     assert 0 < unique_share < 1, "unique_share must be in next bounds: (0; 1)"
    136 
--> 137     unique_elements = set(islice(arg, check_count))
    138     if len(unique_elements) > check_count * unique_share:
    139         do_caching = False

TypeError: unhashable type: 'numpy.ndarray'

采购订单栏信息如下:

purchase_order_id
1140     [2017-04-10]
1148     [2017-07-01]
1151     [2017-05-30]
3156     [2017-10-13]
3363     [2017-09-08]
             ...     
56584    [2019-09-30]
56585    [2019-09-30]
56586    [2019-09-23]
56587    [2019-09-23]
56588    [2019-09-23]

编辑: 数据类型是 ('O') 我曾尝试使用 pd.to_datetime 方法和:

bookings_ship_time['purchase_order_requested_cargo_ready_date'] = datetime.strptime(bookings_ship_time['purchase_order_requested_cargo_ready_date'], '%Y/%m/%d')

0 个答案:

没有答案