[英]How to create a column in pandas based on more than two column conditions?
I have almost 10000 of rows in my data frame.我的数据框中有近 10000 行。 I have columns Date, Time and value.
我有日期、时间和值列。 I want to create a column which carries a value from value column conditional on the same Date and fixed time.
我想创建一个列,该列在同一日期和固定时间有条件地从值列中携带一个值。
Here, I am attaching my data frames for your understanding purpose.在这里,我附上我的数据框以供您理解。 Please note that original data comprises for more than a year for each date and 15 minutes time interval.
请注意,原始数据包括每个日期超过一年和 15 分钟的时间间隔。
Any help is appreciable in advance.任何帮助都是事先得到的。 I want df_2 from df_1.
我想要来自 df_1 的 df_2。 A, B and C are the date, Time and Value columns respectively.
A、B 和 C 分别是日期、时间和值列。
Assuming that both A and B columns are strings , the solution is quite simple.假设A和B列都是strings ,解决方案非常简单。 Just:
只是:
df['D'] = df.groupby([df.A + df.B.str[0:2]]).transform('first')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.