I want to forward fill the NaN in "A" column until all 3 columns are equals.
Using Windows and Python 3.13.3.
Use .ffill()
for DataFrame
Do iterate for DataFrame to check 2 columns are equals.
Snippet:
tydf['A'] = df['A'].ffill()
for i in range(len(df)):
if pd.isna(df.at[df.index[i], 'A']):
# Check if B and C are equal
if df.at[df.index[i], 'B'] == df.at[df.index[i], 'C']:
df.at[df.index[i], 'A'] = df.at[df.index[i], 'B']pe here
Output:
2025-05-22 00:00:00 sell buy sell
2025-05-22 00:15:00 sell buy sell
2025-05-22 00:30:00 sell sell sell
2025-05-22 00:45:00 sell buy sell
2025-05-22 01:00:00 sell buy buy
2025-05-22 01:15:00 buy NaN sell
2025-05-22 01:30:00 buy buy sell
2025-05-22 01:45:00 buy buy buy
2025-05-22 02:00:00 buy buy buy
2025-05-22 02:15:00 buy NaN NaN