简体   繁体   English

pandas如何根据两个以上的列条件创建列?

[英]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 分别是日期、时间和值列。

  • List item项目清单

Assuming that both A and B columns are strings , the solution is quite simple.假设AB列都是strings ,解决方案非常简单。 Just:只是:

df['D'] = df.groupby([df.A + df.B.str[0:2]]).transform('first')

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

相关问题 如何根据此 Pandas 数据框中的列条件创建新的索引行? - How to create new index lines based on column conditions in this pandas dataframe? pandas根据另一列中的值创建一个列,该列选择作为条件 - pandas create a column based on values in another column which selected as conditions 如何基于现有列熊猫的多个条件创建新列 - How to create new column based on multiple conditions from existing column pandas 如何在具有条件的能力的情况下在数据框中创建新列? - How to create new column in dataframe with more than condition while having ability to scale the conditions? 根据许多数字列(熊猫)上的条件创建单个分类列 - Create a single categorical column based on conditions on many numerical columns (pandas) np.select 有两个以上的熊猫列 - np.select with more than two pandas column 如何使用基于上一行和下一行的条件在 Pandas Dataframe 上创建新列? - How can I create a new column on a Pandas Dataframe with conditions based on previous and next row? 如何按两列条件分组拆分数据 pandas - how to split data in groups by two column conditions pandas 熊猫根据每个组的另一列的多个条件创建一个布尔列 - pandas create a boolean column based on multiple conditions on another column for each group 根据条件熊猫在栏中填写空白 - fill blanks in a column based on conditions pandas
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM