-1

I want to apply diffs down columns for a pandas dataframe. EX:

A      B      C
23   40000    1
24    nan    nan
nan  42000    2

I would want something like:

A    B       C
23  40000    1
24  40000    1
24  42000    2

I have tried variations of pandas groupby. I think this is probably the right approach. (or applying some function down columns, but not sure if this is efficient correct me if i'm wrong)

I was able to "apply diffs down the column" and get something like:

A     B     C
24  42000   2

by calling: df = df.groupby('col', as_index=False).last() for each column, but this is not what I am looking for. I am not a pandas expert so apologies if this is a silly question.

Explained above

Dave
  • 21
  • 1
  • 4

1 Answers1

0

Look at this: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.fillna.html

df = df.fillna(method='ffill')

STS
  • 26
  • 2