简体   繁体   English

类型错误:strptime() 参数 1 必须是 str,而不是浮点数

[英]TypeError: strptime() argument 1 must be str, not float

I'm having parsing errors on my code, below is the code and almost understandable dataset我的代码有解析错误,下面是代码和几乎可以理解的数据集

import numpy as np
import pandas as pd
from datetime import datetime as dt

data0 = pd.read_csv('2009-10.csv')
data1 = pd.read_csv('2010-11.csv')

def parse_date(date):
    if date == '':
        return None
    else:
        return dt.strptime(date, '%d/%m/%y').date()

data0.Date = data0.Date.apply(parse_date)
data1.Date = data1.Date.apply(parse_date)

TypeError: strptime() argument 1 must be str, not float类型错误:strptime() 参数 1 必须是 str,而不是浮点数

Date    HomeTeam    AwayTeam    FTHG    FTAG    FTR HTHG    HTAG    HTR Referee HS  AS  HST AST HF  AF  HC  AC  HY  AY  HR  AR  B365H   B365D   B365A
15/08/09    Aston Villa Wigan   0   2   A   0   1   A   M Clattenburg   11  14  5   7   15  14  4   6   2   2   0   0   1.67    3.6 5.5
15/08/09    Blackburn   Man City    0   2   A   0   1   A   M Dean  17  8   9   5   12  9   5   4   2   1   0   0   3.6 3.25    2.1
15/08/09    Bolton  Sunderland  0   1   A   0   1   A   A Marriner  11  20  3   13  16  10  4   7   2   1   0   0   2.25    3.25    3.25
15/08/09    Chelsea Hull    2   1   H   1   1   D   A Wiley 26  7   12  3   13  15  12  4   1   2   0   0   1.17    6.5 21
15/08/09    Everton Arsenal 1   6   A   0   3   A   M Halsey    8   15  5   9   11  13  4   9   0   0   0   0   3.2 3.25    2.3

Date    HomeTeam    AwayTeam    FTHG    FTAG    FTR HTHG    HTAG    HTR Referee HS  AS  HST AST HF  AF  HC  AC  HY  AY  HR  AR  B365H   B365D   B365A
14/08/10    Aston Villa West Ham    3   0   H   2   0   H   M Dean  23  12  11  2   15  15  16  7   1   2   0   0   2   3.3 4
14/08/10    Blackburn   Everton 1   0   H   1   0   H   P Dowd  7   17  2   12  19  14  1   3   2   1   0   0   2.88    3.25    2.5
14/08/10    Bolton  Fulham  0   0   D   0   0   D   S Attwell   13  12  9   7   12  13  4   8   1   3   0   0   2.2 3.3 3.4
14/08/10    Chelsea West Brom   6   0   H   2   0   H   M Clattenburg   18  10  13  4   10  10  3   1   1   0   0   0   1.17    7   17
14/08/10    Sunderland  Birmingham  2   2   D   1   0   H   A Taylor    6   13  2   7   13  10  3   6   3   3   1   0   2.1 3.3 3.6
14/08/10    Tottenham   Man City    0   0   D   0   0   D   A Marriner  22  11  18  7   13  16  10  3   0   2   0   0   2.4 3.3 3

IIUC, I think you are converting strings into datetime dtypes. IIUC,我认为您正在将字符串转换为 datetime dtypes。

You can use Pandas to_datetime :您可以使用熊猫to_datetime

data0['Date'] = pd.to_datetime(data0['Date'], format='%d/%m/%y')
data1['Date'] = pd.to_datetime(data1['Date'], format='%d/%m/%y')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 `TypeError:strptime()参数0必须是str,而不是 <class 'bytes'> ` - `TypeError: strptime() argument 0 must be str, not <class 'bytes'>` Datetime(TypeError:strptime() 参数 1 必须是 str,而不是 Timestamp) - Datetime (TypeError: strptime() argument 1 must be str, not Timestamp) 将loadtxt列转换为工作日:TypeError:strptime()参数1必须为str,而不是字节 - Converting a loadtxt column to a weekday: TypeError: strptime() argument 1 must be str, not bytes TypeError:strptime() 参数 1 必须是 str,而不是 tweepy 中的 datetime.datetime - TypeError: strptime() argument 1 must be str, not datetime.datetime in tweepy 如何解决错误“ TypeError:strptime()参数1必须为str,而不是布尔值” - How to resolve error “TypeError: strptime() argument 1 must be str, not bool” strptime() 参数 1 必须是 str,而不是 Series - strptime() argument 1 must be str, not Series 如何处理TypeError:必须为str,而不是float - How to deal with TypeError: must be str, not float TypeError:LoadLibrary() 参数 1 必须是 str,而不是 None - TypeError:LoadLibrary() argument 1 must be str, not None 类型错误:write() 参数必须是 str,而不是 HTTPResponse - TypeError: write() argument must be str, not HTTPResponse 类型错误:float() 参数必须是字符串或数字,而不是“模块” - TypeError: float() argument must be a string or a number, not 'module'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM