0

I was able to filter the data frame but could not get to generate columns with suffice the given condition in code.

My Trial:

import pandas as pd
from pandas import Timestamp
import re,datetime

df1 = pd.DataFrame({'A': {0: Timestamp('2021-02-13 00:00:00'), 1: Timestamp('2021-02-14 00:00:00'), 2: Timestamp('2021-02-15 00:00:00'), 3: Timestamp('2021-02-16 00:00:00'), 4: Timestamp('2021-02-17 00:00:00')}, 'B': {0: Timestamp('2021-02-13 00:00:00'), 1: Timestamp('2021-02-14 00:00:00'), 2: Timestamp('2021-02-13 00:00:00'), 3: Timestamp('2021-02-13 00:00:00'), 4: Timestamp('2021-02-13 00:00:00')}, 'C': {0: 'C0', 1: 'C1', 2: 'C2', 3: 'C3', 4: 'C4'}})

df2 = df1[(df1.A > df1.B)]
#df2["D"] = df1[(df1.A > df1.B)]
print (df2)

Expected Output:

enter image description here

OO7
  • 350
  • 2
  • 12
  • 2
    Use `np.where`: `df['D'] = np.where((df1.A > df1.B),"Yes","No")` – anky Feb 13 '21 at 07:05
  • Thinking of what is missing in the syntax df1["D"] = df1[(df1.A > df1.B)] to get the expected output. – OO7 Feb 13 '21 at 07:19

0 Answers0