79639367

Date: 2025-05-26 17:36:14
Score: 0.5
Natty:
Report link

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
Reasons:
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Adios Gringo