简体   繁体   English

如何从另一个Pandas时间序列创建Pandas数据框列?

[英]How can I create a Pandas Dataframe column from another Pandas Timeseries?

I have a Dataframe with Datetime columns: 我有一个带有Datetime列的Dataframe:

Parcela     DS1        DC1         DS0        DC0
P1      2016-04-26  2016-09-26  2016-04-11  2016-09-11
P2      2016-04-26  2016-09-26  2016-04-11  2016-09-11

I've tried to create a new column with the following code: 我尝试使用以下代码创建新列:

df['sem'] = prec[df['DS0'].dt.strftime('%Y-%m%d'):df['DS1'].dt.strftime('%Y-%m-%d')].sum()

where prec is another dataframe with a datetime index, 其中prec是具有日期时间索引的另一个数据框,

 Datetime               prec
 2016-04-13 00:00:00    0.0
 2016-04-13 00:10:00    0.0

but I get the following error 但我收到以下错误

Cannot convert input of type <class 'pandas.core.series.Series'> to Timestamp

Could you help me? 你可以帮帮我吗?

您可以向

df['sem'] = [prec.loc[x:y,'prec'].sum() for x , y in zip(df['DS0'].dt.strftime('%Y-%m%d'),df['DS1'].dt.strftime('%Y-%m-%d'))]

暂无
暂无

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

相关问题 如何将Pandas DataFrame转换为TimeSeries? - How can I convert from Pandas DataFrame to TimeSeries? 如何从 Pandas (Python) 中的排序时间序列索引的数据帧中的列中的所有值生成统计特征? - How can I generate statistical features from all values in a column from dataframe indexed by a sorted timeseries in Pandas (Python)? 如何通过拆分从数据框中的另一列创建 Pandas 数据框? - How to create a Pandas dataframe from another column in a dataframe by splitting it? 如何在另一个数据帧 python pandas 中的多列上使用条件逻辑在数据帧中创建一列? - How can I create a column in a dataframe using conditional logic on multiple columns in another dataframe python pandas? 我如何 pivot 和 pandas Z6A8064B5DF4794555500553C47C55057DZ (时间序列)同时具有多个列? - How can I pivot a pandas dataframe (timeseries) with multiple columns at once? 如何根据 pandas dataframe 中另一列的多个值在一列中创建值列表? - How do I create a list of values in a column from several values from another column in a pandas dataframe? 如何使用来自另一列的数据创建新的Pandas Dataframe列 - How do I create a new Pandas Dataframe Column with data from another column 如何遍历pandas DataFrame的一列并从另一列返回值? - How can I iterate through a column of a pandas DataFrame and return value from another column? Pandas DataFrame:如何从另一列的数值中创建数值? - Pandas DataFrame: How do I create numerical values out of numerical values from another column? 如何基于带有日期的另一列创建 Pandas 列? - How can I create a Pandas column based on another column with a date?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM