-1

I have almost 10000 of rows in my data frame. 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.

Any help is appreciable in advance. I want df_2 from df_1. A, B and C are the date, Time and Value columns respectively.

  • List item
  • 1
    Dont add pictures of your data, we cannot copy pictures. Read [this](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). Add your data in the form of `pd.DataFrame..`, so we can copy and produce an answer for you – Erfan Sep 28 '19 at 21:31
  • You are looking for `groupby` + `transform` + `first`. But without data that can be easily copied, it's a lot of work to give more advice than that. – ALollz Sep 28 '19 at 22:32

1 Answers1

1

Assuming that both A and B columns are strings, the solution is quite simple. Just:

df['D'] = df.groupby([df.A + df.B.str[0:2]]).transform('first')
Valdi_Bo
  • 30,023
  • 4
  • 23
  • 41