简体   繁体   English

如何在 Pandas DataFrame 中通过另一个重新定义日期时间数据?

[英]How to redefine datetime data by another in Pandas DataFrame?

I got this Pandas Dataframe data .我得到了这个Pandas Dataframe data Inside, in the start column i have date in datetime format.在内部,在开始列中我有日期时间格式的日期。 In the duration column i have a timedelta format.在持续时间列中,我有一个 timedelta 格式。 What i whanted to do is to get new datetime in the second line, [by doing 0:00+0:20=0:20.我想做的是在第二行获得新的日期时间,[通过执行 0:00+0:20=0:20。

But when i tried to data["start"][1] = data["start"][0] + data["duration"][0] i recieve SettingWithCopyWarning Error.但是当我尝试data["start"][1] = data["start"][0] + data["duration"][0]我收到SettingWithCopyWarning错误。

Or data["start"][2] = data["start"][1] + data["duration"][1] .或者data["start"][2] = data["start"][1] + data["duration"][1] But it still works .但它仍然有效 I wonder have can i fix this?我想知道我可以解决这个问题吗?

You can use .loc as follows:您可以按如下方式使用.loc

data.loc[1, "start"] = data.loc[0, "start"] + data.loc[0, "duration"]

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

相关问题 如何使用增量日期时间模拟 pandas dataframe 数据 - how to simulate pandas dataframe data with increment datetime 在 Python Pandas 中,如何在 datetime 列上加入另一个由 periodindex 索引的数据帧? - In Python Pandas, how to join on a datetime column another dataframe that is indexed by a periodindex? Python Pandas Dataframe:基于DateTime条件,我想用来自另一个数据框的数据填充一个数据框 - Python Pandas Dataframe: based on DateTime criteria, I would like to populate a dataframe with data from another dataframe PANDAS(在 pandas 的 dataframe 中填充 datetime 和 ffill() 数据) - PANDAS (poputating datetime and ffill() the data in dataframe in pandas) 如何按日期时间索引 pandas dataframe? - How to index a pandas dataframe by datetime? 如何在熊猫数据框中索引DateTime - How to index DateTime in Pandas dataframe 如何使用另一个日期时间索引获取带有日期时间索引的 Pandas 数据框中的行? - How to get the rows in Pandas dataframe with datetime index using another datetime index? 我应该为每个函数重新定义一个 Pandas 数据框吗? - Should I redefine a pandas dataframe with every function? 根据熊猫数据框中的日期时间选择数据 - select data based on datetime in pandas dataframe 通过 pandas dataframe 中的日期时间迭代 plot 数据 - Iteratively plot data through datetime in pandas dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM