Reputation: 316
I am a freshman in Python and Python Pandas.
This is my dataframe
date open high low close volume
0 2020-09-02 12:55:00+00:00 0.038904 0.038940 0.038833 0.038840 1233.725
1 2020-09-02 13:00:00+00:00 0.038838 0.038940 0.038741 0.038873 1637.552
2 2020-09-02 13:05:00+00:00 0.038866 0.038988 0.038862 0.038980 1196.561
3 2020-09-02 13:10:00+00:00 0.038985 0.039022 0.038919 0.039017 1527.921
4 2020-09-02 13:15:00+00:00 0.039020 0.039200 0.039000 0.039101 3741.821
How can make new column
I wish make like this
up = max(close - close.shift(1), 0)
Thanks you in advice
Upvotes: 1
Views: 32
Reputation: 862511
I think you need Series.diff
instead subtract shifted values and then Series.clip
for convert negative values to 0
:
df['new'] = df.close.diff().clip(lower=0)
Upvotes: 1