我有一个列,我已经使用pandas转换为datetime,所以现在它的格式为datetime64.
LOCAL_TIME_ON
2014-06-21 15:32:09
2014-06-07 20:17:13
Run Code Online (Sandbox Code Playgroud)
我想将小时提取到一个新列.我发现唯一有效的方法是下面的,但是,我得到了一个SettingWithCopyWarning.有没有人有一个更干净的方式我可以做到这一点?
TRIP_INFO_TIME['TIME_HOUR'] = pd.DatetimeIndex(TRIP_INFO_TIME['LOCAL_TIME_ON']).hour.astype(int)
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.1.4\helpers\pydev\pydevconsole.py:1: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy '''
试试这个:
TRIP_INFO_TIME['TIME_HOUR'] = TRIP_INFO_TIME['LOCAL_TIME_ON'].dt.hour
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2242 次 |
| 最近记录: |