Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 有没有像pd.to\u datetime这样的方法?_Python_Pandas - Fatal编程技术网

Python 有没有像pd.to\u datetime这样的方法?

Python 有没有像pd.to\u datetime这样的方法?,python,pandas,Python,Pandas,我想知道是否有像pd.to_datetime这样的方法,也就是说,我想有像df['column1']这样的方法。to_datetime()考虑以下数据帧: import pandas as pd import datetime raw_data = {'Player': ['Matthew', 'John', 'Lisa', 'Taylor', 'Matthew', 'John', 'Lisa', 'Taylor',

我想知道是否有像pd.to_datetime这样的方法,也就是说,我想有像df['column1']这样的方法。to_datetime()

考虑以下数据帧:

import pandas as pd
import datetime
raw_data = {'Player':      ['Matthew', 'John', 'Lisa', 'Taylor', 
                        'Matthew', 'John', 'Lisa', 'Taylor',
                        'Matthew', 'John', 'Lisa', 'Taylor',
                        'Matthew', 'John', 'Lisa', 'Taylor'],

        'Race Number': [1, 1, 1, 1, 
                        2, 2, 2, 2,
                        3, 3, 3, 3,
                        4, 4, 4, 4],

        'Place':       [2, 1, 3, 4,
                        3, 2, 4, 1,
                        1, 3, 4, 2,
                        2, 1, 3, 4],

       'Date of Race': ['1/1/2019','1/1/2019','1/1/2019','1/1/2019',
                        '1/2/2019','1/2/2019','1/2/2019','1/2/2019',
                        '1/3/2019','1/3/2019','1/3/2019','1/3/2019',
                        '1/4/2019','1/4/2019','1/4/2019','1/4/2019'            
       ]}

mariokartdata = pd.DataFrame(raw_data)
mariokartdata.dtypes
这将返回:

Player          object
Race Number      int64
Place            int64
Date of Race    object
但如果你跑步:

mariokartdata['Date of Race'] = pd.to_datetime(mariokartdata['Date of Race'])
mariokartdata.dtypes
现在它将返回:

Player                  object
Race Number              int64
Place                    int64
Date of Race    datetime64[ns]

从而为列['Date of Race']创建日期时间值

pd.to_datetime(df['column1'])
:只需将其作为参数传递,因此
pd.to_datetime(df['mycolumn'])
。我理解它。我只是想知道,现在是否有一个方法,而不是一个函数,它是一个高级函数,而不是一个系列属性