Copy Previous Row Values when Current Value is 0 (Zero)
up vote
2
down vote
favorite
My Dataframe as below:
13664567 74.3 SELL 1581566.4 2378211.6 12:07:59
13665406 74.3 0 0 0 0
13665406 0 0 0 0 0
13665406 74.3 0 0 0 0
13667531 74.3 0 0 0 0
13667531 74.3 0 0 0 0
13672281 74.3 0 0 0 0
13672591 74.3 0 0 0 0
13672591 74.3 BUY 2388742.8 1590276 12:08:01
13681398 74.3 0 0 0 0
13681398 74.3 0 0 0 0
13684573 74.3 0 0 0 0
13685574 74.3 0 0 0 0
13685574 74.3 0 0 0 0
13688544 0 0 0 0 0
13689596 74.3 0 0 0 0
13689596 74.3 0 0 0 0
13705735 74.3 0 0 0 0
13706035 74.3 0 0 0 0
13712130 74.3 SELL 1583219.2 2408620.8 12:08:01
13712130 74.3 0 0 0 0
13715699 74.3 0 0 0 0
13720809 74.3 0 0 0 0
13726310 74.3 0 0 0 0
13726310 74.3 0 0 0 0
13726410 74.3 0 0 0 0
I want to fill the 0 (Zero) values of last 4 Columns with previous row values.
I want dataframe like as below:
13664567 74.3 SELL 1581566.4 2378212 12:07:59
13665406 74.3 SELL 1581566.4 2378212 12:07:59
13665406 0 SELL 1581566.4 2378212 12:07:59
13665406 74.3 SELL 1581566.4 2378212 12:07:59
13667531 74.3 SELL 1581566.4 2378212 12:07:59
13667531 74.3 SELL 1581566.4 2378212 12:07:59
13672281 74.3 SELL 1581566.4 2378212 12:07:59
13672591 74.3 SELL 1581566.4 2378212 12:07:59
13672591 74.3 BUY 2388742.8 1590276 12:08:01
13681398 74.3 BUY 2388742.8 1590276 12:08:01
13681398 74.3 BUY 2388742.8 1590276 12:08:01
13684573 74.3 BUY 2388742.8 1590276 12:08:01
13685574 74.3 BUY 2388742.8 1590276 12:08:01
13685574 74.3 BUY 2388742.8 1590276 12:08:01
13688544 0 BUY 2388742.8 1590276 12:08:01
13689596 74.3 BUY 2388742.8 1590276 12:08:01
13689596 74.3 BUY 2388742.8 1590276 12:08:01
13705735 74.3 BUY 2388742.8 1590276 12:08:01
13706035 74.3 BUY 2388742.8 1590276 12:08:01
13712130 74.3 SELL 1583219.2 2408621 12:08:01
13712130 74.3 SELL 1583219.2 2408621 12:08:01
13715699 74.3 SELL 1583219.2 2408621 12:08:01
13720809 74.3 SELL 1583219.2 2408621 12:08:01
13726310 74.3 SELL 1583219.2 2408621 12:08:01
13726310 74.3 SELL 1583219.2 2408621 12:08:01
13726410 74.3 SELL 1583219.2 2408621 12:08:01
I want to make the changes only to last four columns and copy the previous row values to next row until the New Value is available.
Please help.
python python-3.x dataframe
add a comment |
up vote
2
down vote
favorite
My Dataframe as below:
13664567 74.3 SELL 1581566.4 2378211.6 12:07:59
13665406 74.3 0 0 0 0
13665406 0 0 0 0 0
13665406 74.3 0 0 0 0
13667531 74.3 0 0 0 0
13667531 74.3 0 0 0 0
13672281 74.3 0 0 0 0
13672591 74.3 0 0 0 0
13672591 74.3 BUY 2388742.8 1590276 12:08:01
13681398 74.3 0 0 0 0
13681398 74.3 0 0 0 0
13684573 74.3 0 0 0 0
13685574 74.3 0 0 0 0
13685574 74.3 0 0 0 0
13688544 0 0 0 0 0
13689596 74.3 0 0 0 0
13689596 74.3 0 0 0 0
13705735 74.3 0 0 0 0
13706035 74.3 0 0 0 0
13712130 74.3 SELL 1583219.2 2408620.8 12:08:01
13712130 74.3 0 0 0 0
13715699 74.3 0 0 0 0
13720809 74.3 0 0 0 0
13726310 74.3 0 0 0 0
13726310 74.3 0 0 0 0
13726410 74.3 0 0 0 0
I want to fill the 0 (Zero) values of last 4 Columns with previous row values.
I want dataframe like as below:
13664567 74.3 SELL 1581566.4 2378212 12:07:59
13665406 74.3 SELL 1581566.4 2378212 12:07:59
13665406 0 SELL 1581566.4 2378212 12:07:59
13665406 74.3 SELL 1581566.4 2378212 12:07:59
13667531 74.3 SELL 1581566.4 2378212 12:07:59
13667531 74.3 SELL 1581566.4 2378212 12:07:59
13672281 74.3 SELL 1581566.4 2378212 12:07:59
13672591 74.3 SELL 1581566.4 2378212 12:07:59
13672591 74.3 BUY 2388742.8 1590276 12:08:01
13681398 74.3 BUY 2388742.8 1590276 12:08:01
13681398 74.3 BUY 2388742.8 1590276 12:08:01
13684573 74.3 BUY 2388742.8 1590276 12:08:01
13685574 74.3 BUY 2388742.8 1590276 12:08:01
13685574 74.3 BUY 2388742.8 1590276 12:08:01
13688544 0 BUY 2388742.8 1590276 12:08:01
13689596 74.3 BUY 2388742.8 1590276 12:08:01
13689596 74.3 BUY 2388742.8 1590276 12:08:01
13705735 74.3 BUY 2388742.8 1590276 12:08:01
13706035 74.3 BUY 2388742.8 1590276 12:08:01
13712130 74.3 SELL 1583219.2 2408621 12:08:01
13712130 74.3 SELL 1583219.2 2408621 12:08:01
13715699 74.3 SELL 1583219.2 2408621 12:08:01
13720809 74.3 SELL 1583219.2 2408621 12:08:01
13726310 74.3 SELL 1583219.2 2408621 12:08:01
13726310 74.3 SELL 1583219.2 2408621 12:08:01
13726410 74.3 SELL 1583219.2 2408621 12:08:01
I want to make the changes only to last four columns and copy the previous row values to next row until the New Value is available.
Please help.
python python-3.x dataframe
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
My Dataframe as below:
13664567 74.3 SELL 1581566.4 2378211.6 12:07:59
13665406 74.3 0 0 0 0
13665406 0 0 0 0 0
13665406 74.3 0 0 0 0
13667531 74.3 0 0 0 0
13667531 74.3 0 0 0 0
13672281 74.3 0 0 0 0
13672591 74.3 0 0 0 0
13672591 74.3 BUY 2388742.8 1590276 12:08:01
13681398 74.3 0 0 0 0
13681398 74.3 0 0 0 0
13684573 74.3 0 0 0 0
13685574 74.3 0 0 0 0
13685574 74.3 0 0 0 0
13688544 0 0 0 0 0
13689596 74.3 0 0 0 0
13689596 74.3 0 0 0 0
13705735 74.3 0 0 0 0
13706035 74.3 0 0 0 0
13712130 74.3 SELL 1583219.2 2408620.8 12:08:01
13712130 74.3 0 0 0 0
13715699 74.3 0 0 0 0
13720809 74.3 0 0 0 0
13726310 74.3 0 0 0 0
13726310 74.3 0 0 0 0
13726410 74.3 0 0 0 0
I want to fill the 0 (Zero) values of last 4 Columns with previous row values.
I want dataframe like as below:
13664567 74.3 SELL 1581566.4 2378212 12:07:59
13665406 74.3 SELL 1581566.4 2378212 12:07:59
13665406 0 SELL 1581566.4 2378212 12:07:59
13665406 74.3 SELL 1581566.4 2378212 12:07:59
13667531 74.3 SELL 1581566.4 2378212 12:07:59
13667531 74.3 SELL 1581566.4 2378212 12:07:59
13672281 74.3 SELL 1581566.4 2378212 12:07:59
13672591 74.3 SELL 1581566.4 2378212 12:07:59
13672591 74.3 BUY 2388742.8 1590276 12:08:01
13681398 74.3 BUY 2388742.8 1590276 12:08:01
13681398 74.3 BUY 2388742.8 1590276 12:08:01
13684573 74.3 BUY 2388742.8 1590276 12:08:01
13685574 74.3 BUY 2388742.8 1590276 12:08:01
13685574 74.3 BUY 2388742.8 1590276 12:08:01
13688544 0 BUY 2388742.8 1590276 12:08:01
13689596 74.3 BUY 2388742.8 1590276 12:08:01
13689596 74.3 BUY 2388742.8 1590276 12:08:01
13705735 74.3 BUY 2388742.8 1590276 12:08:01
13706035 74.3 BUY 2388742.8 1590276 12:08:01
13712130 74.3 SELL 1583219.2 2408621 12:08:01
13712130 74.3 SELL 1583219.2 2408621 12:08:01
13715699 74.3 SELL 1583219.2 2408621 12:08:01
13720809 74.3 SELL 1583219.2 2408621 12:08:01
13726310 74.3 SELL 1583219.2 2408621 12:08:01
13726310 74.3 SELL 1583219.2 2408621 12:08:01
13726410 74.3 SELL 1583219.2 2408621 12:08:01
I want to make the changes only to last four columns and copy the previous row values to next row until the New Value is available.
Please help.
python python-3.x dataframe
My Dataframe as below:
13664567 74.3 SELL 1581566.4 2378211.6 12:07:59
13665406 74.3 0 0 0 0
13665406 0 0 0 0 0
13665406 74.3 0 0 0 0
13667531 74.3 0 0 0 0
13667531 74.3 0 0 0 0
13672281 74.3 0 0 0 0
13672591 74.3 0 0 0 0
13672591 74.3 BUY 2388742.8 1590276 12:08:01
13681398 74.3 0 0 0 0
13681398 74.3 0 0 0 0
13684573 74.3 0 0 0 0
13685574 74.3 0 0 0 0
13685574 74.3 0 0 0 0
13688544 0 0 0 0 0
13689596 74.3 0 0 0 0
13689596 74.3 0 0 0 0
13705735 74.3 0 0 0 0
13706035 74.3 0 0 0 0
13712130 74.3 SELL 1583219.2 2408620.8 12:08:01
13712130 74.3 0 0 0 0
13715699 74.3 0 0 0 0
13720809 74.3 0 0 0 0
13726310 74.3 0 0 0 0
13726310 74.3 0 0 0 0
13726410 74.3 0 0 0 0
I want to fill the 0 (Zero) values of last 4 Columns with previous row values.
I want dataframe like as below:
13664567 74.3 SELL 1581566.4 2378212 12:07:59
13665406 74.3 SELL 1581566.4 2378212 12:07:59
13665406 0 SELL 1581566.4 2378212 12:07:59
13665406 74.3 SELL 1581566.4 2378212 12:07:59
13667531 74.3 SELL 1581566.4 2378212 12:07:59
13667531 74.3 SELL 1581566.4 2378212 12:07:59
13672281 74.3 SELL 1581566.4 2378212 12:07:59
13672591 74.3 SELL 1581566.4 2378212 12:07:59
13672591 74.3 BUY 2388742.8 1590276 12:08:01
13681398 74.3 BUY 2388742.8 1590276 12:08:01
13681398 74.3 BUY 2388742.8 1590276 12:08:01
13684573 74.3 BUY 2388742.8 1590276 12:08:01
13685574 74.3 BUY 2388742.8 1590276 12:08:01
13685574 74.3 BUY 2388742.8 1590276 12:08:01
13688544 0 BUY 2388742.8 1590276 12:08:01
13689596 74.3 BUY 2388742.8 1590276 12:08:01
13689596 74.3 BUY 2388742.8 1590276 12:08:01
13705735 74.3 BUY 2388742.8 1590276 12:08:01
13706035 74.3 BUY 2388742.8 1590276 12:08:01
13712130 74.3 SELL 1583219.2 2408621 12:08:01
13712130 74.3 SELL 1583219.2 2408621 12:08:01
13715699 74.3 SELL 1583219.2 2408621 12:08:01
13720809 74.3 SELL 1583219.2 2408621 12:08:01
13726310 74.3 SELL 1583219.2 2408621 12:08:01
13726310 74.3 SELL 1583219.2 2408621 12:08:01
13726410 74.3 SELL 1583219.2 2408621 12:08:01
I want to make the changes only to last four columns and copy the previous row values to next row until the New Value is available.
Please help.
python python-3.x dataframe
python python-3.x dataframe
edited Nov 4 at 10:21
asked Nov 4 at 10:11
Pravat
698
698
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
Use update
with select last 4 columns by iloc
, replace by missing values and forward fill last previous values:
df.update(df.iloc[:, -4:].replace([0,'0'], np.nan).ffill())
Or use mask
for replace 0
:
df.update(df.iloc[:, -4:].mask(lambda x: x.isin([0, '0'])).ffill())
#if no string 0
#df.update(df.iloc[:, -4:].mask(lambda x: x == 0)).ffill())
print (df)
a b c d e f
0 13664567 74.3 SELL 1581566.4 2378211.6 12:07:59
1 13665406 74.3 SELL 1581566.4 2378211.6 12:07:59
2 13665406 74.3 SELL 1581566.4 2378211.6 12:07:59
3 13665406 74.3 SELL 1581566.4 2378211.6 12:07:59
4 13667531 74.3 SELL 1581566.4 2378211.6 12:07:59
5 13667531 74.3 SELL 1581566.4 2378211.6 12:07:59
6 13672281 74.3 SELL 1581566.4 2378211.6 12:07:59
7 13672591 74.3 SELL 1581566.4 2378211.6 12:07:59
8 13672591 74.3 BUY 2388742.8 1590276.0 12:08:01
9 13681398 74.3 BUY 2388742.8 1590276.0 12:08:01
10 13681398 74.3 BUY 2388742.8 1590276.0 12:08:01
11 13684573 74.3 BUY 2388742.8 1590276.0 12:08:01
12 13685574 74.3 BUY 2388742.8 1590276.0 12:08:01
13 13685574 74.3 BUY 2388742.8 1590276.0 12:08:01
14 13688544 74.3 BUY 2388742.8 1590276.0 12:08:01
15 13689596 74.3 BUY 2388742.8 1590276.0 12:08:01
16 13689596 74.3 BUY 2388742.8 1590276.0 12:08:01
17 13705735 74.3 BUY 2388742.8 1590276.0 12:08:01
18 13706035 74.3 BUY 2388742.8 1590276.0 12:08:01
19 13712130 74.3 SELL 1583219.2 2408620.8 12:08:01
20 13712130 74.3 SELL 1583219.2 2408620.8 12:08:01
21 13715699 74.3 SELL 1583219.2 2408620.8 12:08:01
22 13720809 74.3 SELL 1583219.2 2408620.8 12:08:01
23 13726310 74.3 SELL 1583219.2 2408620.8 12:08:01
24 13726310 74.3 SELL 1583219.2 2408620.8 12:08:01
25 13726410 74.3 SELL 1583219.2 2408620.8 12:08:01
1
Sir, Is it possible to select particular columns as I want to apply to last 4 columns only.
– Pravat
Nov 4 at 10:16
1
@Pravat - Super, glad can help! :)
– jezrael
Nov 4 at 10:32
add a comment |
up vote
1
down vote
You can use mask
+ ffill
:
values = df.iloc[:, -4:]
df.iloc[:, -4:] = values.mask(values.isin([0, '0'])).ffill()
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
Use update
with select last 4 columns by iloc
, replace by missing values and forward fill last previous values:
df.update(df.iloc[:, -4:].replace([0,'0'], np.nan).ffill())
Or use mask
for replace 0
:
df.update(df.iloc[:, -4:].mask(lambda x: x.isin([0, '0'])).ffill())
#if no string 0
#df.update(df.iloc[:, -4:].mask(lambda x: x == 0)).ffill())
print (df)
a b c d e f
0 13664567 74.3 SELL 1581566.4 2378211.6 12:07:59
1 13665406 74.3 SELL 1581566.4 2378211.6 12:07:59
2 13665406 74.3 SELL 1581566.4 2378211.6 12:07:59
3 13665406 74.3 SELL 1581566.4 2378211.6 12:07:59
4 13667531 74.3 SELL 1581566.4 2378211.6 12:07:59
5 13667531 74.3 SELL 1581566.4 2378211.6 12:07:59
6 13672281 74.3 SELL 1581566.4 2378211.6 12:07:59
7 13672591 74.3 SELL 1581566.4 2378211.6 12:07:59
8 13672591 74.3 BUY 2388742.8 1590276.0 12:08:01
9 13681398 74.3 BUY 2388742.8 1590276.0 12:08:01
10 13681398 74.3 BUY 2388742.8 1590276.0 12:08:01
11 13684573 74.3 BUY 2388742.8 1590276.0 12:08:01
12 13685574 74.3 BUY 2388742.8 1590276.0 12:08:01
13 13685574 74.3 BUY 2388742.8 1590276.0 12:08:01
14 13688544 74.3 BUY 2388742.8 1590276.0 12:08:01
15 13689596 74.3 BUY 2388742.8 1590276.0 12:08:01
16 13689596 74.3 BUY 2388742.8 1590276.0 12:08:01
17 13705735 74.3 BUY 2388742.8 1590276.0 12:08:01
18 13706035 74.3 BUY 2388742.8 1590276.0 12:08:01
19 13712130 74.3 SELL 1583219.2 2408620.8 12:08:01
20 13712130 74.3 SELL 1583219.2 2408620.8 12:08:01
21 13715699 74.3 SELL 1583219.2 2408620.8 12:08:01
22 13720809 74.3 SELL 1583219.2 2408620.8 12:08:01
23 13726310 74.3 SELL 1583219.2 2408620.8 12:08:01
24 13726310 74.3 SELL 1583219.2 2408620.8 12:08:01
25 13726410 74.3 SELL 1583219.2 2408620.8 12:08:01
1
Sir, Is it possible to select particular columns as I want to apply to last 4 columns only.
– Pravat
Nov 4 at 10:16
1
@Pravat - Super, glad can help! :)
– jezrael
Nov 4 at 10:32
add a comment |
up vote
3
down vote
accepted
Use update
with select last 4 columns by iloc
, replace by missing values and forward fill last previous values:
df.update(df.iloc[:, -4:].replace([0,'0'], np.nan).ffill())
Or use mask
for replace 0
:
df.update(df.iloc[:, -4:].mask(lambda x: x.isin([0, '0'])).ffill())
#if no string 0
#df.update(df.iloc[:, -4:].mask(lambda x: x == 0)).ffill())
print (df)
a b c d e f
0 13664567 74.3 SELL 1581566.4 2378211.6 12:07:59
1 13665406 74.3 SELL 1581566.4 2378211.6 12:07:59
2 13665406 74.3 SELL 1581566.4 2378211.6 12:07:59
3 13665406 74.3 SELL 1581566.4 2378211.6 12:07:59
4 13667531 74.3 SELL 1581566.4 2378211.6 12:07:59
5 13667531 74.3 SELL 1581566.4 2378211.6 12:07:59
6 13672281 74.3 SELL 1581566.4 2378211.6 12:07:59
7 13672591 74.3 SELL 1581566.4 2378211.6 12:07:59
8 13672591 74.3 BUY 2388742.8 1590276.0 12:08:01
9 13681398 74.3 BUY 2388742.8 1590276.0 12:08:01
10 13681398 74.3 BUY 2388742.8 1590276.0 12:08:01
11 13684573 74.3 BUY 2388742.8 1590276.0 12:08:01
12 13685574 74.3 BUY 2388742.8 1590276.0 12:08:01
13 13685574 74.3 BUY 2388742.8 1590276.0 12:08:01
14 13688544 74.3 BUY 2388742.8 1590276.0 12:08:01
15 13689596 74.3 BUY 2388742.8 1590276.0 12:08:01
16 13689596 74.3 BUY 2388742.8 1590276.0 12:08:01
17 13705735 74.3 BUY 2388742.8 1590276.0 12:08:01
18 13706035 74.3 BUY 2388742.8 1590276.0 12:08:01
19 13712130 74.3 SELL 1583219.2 2408620.8 12:08:01
20 13712130 74.3 SELL 1583219.2 2408620.8 12:08:01
21 13715699 74.3 SELL 1583219.2 2408620.8 12:08:01
22 13720809 74.3 SELL 1583219.2 2408620.8 12:08:01
23 13726310 74.3 SELL 1583219.2 2408620.8 12:08:01
24 13726310 74.3 SELL 1583219.2 2408620.8 12:08:01
25 13726410 74.3 SELL 1583219.2 2408620.8 12:08:01
1
Sir, Is it possible to select particular columns as I want to apply to last 4 columns only.
– Pravat
Nov 4 at 10:16
1
@Pravat - Super, glad can help! :)
– jezrael
Nov 4 at 10:32
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
Use update
with select last 4 columns by iloc
, replace by missing values and forward fill last previous values:
df.update(df.iloc[:, -4:].replace([0,'0'], np.nan).ffill())
Or use mask
for replace 0
:
df.update(df.iloc[:, -4:].mask(lambda x: x.isin([0, '0'])).ffill())
#if no string 0
#df.update(df.iloc[:, -4:].mask(lambda x: x == 0)).ffill())
print (df)
a b c d e f
0 13664567 74.3 SELL 1581566.4 2378211.6 12:07:59
1 13665406 74.3 SELL 1581566.4 2378211.6 12:07:59
2 13665406 74.3 SELL 1581566.4 2378211.6 12:07:59
3 13665406 74.3 SELL 1581566.4 2378211.6 12:07:59
4 13667531 74.3 SELL 1581566.4 2378211.6 12:07:59
5 13667531 74.3 SELL 1581566.4 2378211.6 12:07:59
6 13672281 74.3 SELL 1581566.4 2378211.6 12:07:59
7 13672591 74.3 SELL 1581566.4 2378211.6 12:07:59
8 13672591 74.3 BUY 2388742.8 1590276.0 12:08:01
9 13681398 74.3 BUY 2388742.8 1590276.0 12:08:01
10 13681398 74.3 BUY 2388742.8 1590276.0 12:08:01
11 13684573 74.3 BUY 2388742.8 1590276.0 12:08:01
12 13685574 74.3 BUY 2388742.8 1590276.0 12:08:01
13 13685574 74.3 BUY 2388742.8 1590276.0 12:08:01
14 13688544 74.3 BUY 2388742.8 1590276.0 12:08:01
15 13689596 74.3 BUY 2388742.8 1590276.0 12:08:01
16 13689596 74.3 BUY 2388742.8 1590276.0 12:08:01
17 13705735 74.3 BUY 2388742.8 1590276.0 12:08:01
18 13706035 74.3 BUY 2388742.8 1590276.0 12:08:01
19 13712130 74.3 SELL 1583219.2 2408620.8 12:08:01
20 13712130 74.3 SELL 1583219.2 2408620.8 12:08:01
21 13715699 74.3 SELL 1583219.2 2408620.8 12:08:01
22 13720809 74.3 SELL 1583219.2 2408620.8 12:08:01
23 13726310 74.3 SELL 1583219.2 2408620.8 12:08:01
24 13726310 74.3 SELL 1583219.2 2408620.8 12:08:01
25 13726410 74.3 SELL 1583219.2 2408620.8 12:08:01
Use update
with select last 4 columns by iloc
, replace by missing values and forward fill last previous values:
df.update(df.iloc[:, -4:].replace([0,'0'], np.nan).ffill())
Or use mask
for replace 0
:
df.update(df.iloc[:, -4:].mask(lambda x: x.isin([0, '0'])).ffill())
#if no string 0
#df.update(df.iloc[:, -4:].mask(lambda x: x == 0)).ffill())
print (df)
a b c d e f
0 13664567 74.3 SELL 1581566.4 2378211.6 12:07:59
1 13665406 74.3 SELL 1581566.4 2378211.6 12:07:59
2 13665406 74.3 SELL 1581566.4 2378211.6 12:07:59
3 13665406 74.3 SELL 1581566.4 2378211.6 12:07:59
4 13667531 74.3 SELL 1581566.4 2378211.6 12:07:59
5 13667531 74.3 SELL 1581566.4 2378211.6 12:07:59
6 13672281 74.3 SELL 1581566.4 2378211.6 12:07:59
7 13672591 74.3 SELL 1581566.4 2378211.6 12:07:59
8 13672591 74.3 BUY 2388742.8 1590276.0 12:08:01
9 13681398 74.3 BUY 2388742.8 1590276.0 12:08:01
10 13681398 74.3 BUY 2388742.8 1590276.0 12:08:01
11 13684573 74.3 BUY 2388742.8 1590276.0 12:08:01
12 13685574 74.3 BUY 2388742.8 1590276.0 12:08:01
13 13685574 74.3 BUY 2388742.8 1590276.0 12:08:01
14 13688544 74.3 BUY 2388742.8 1590276.0 12:08:01
15 13689596 74.3 BUY 2388742.8 1590276.0 12:08:01
16 13689596 74.3 BUY 2388742.8 1590276.0 12:08:01
17 13705735 74.3 BUY 2388742.8 1590276.0 12:08:01
18 13706035 74.3 BUY 2388742.8 1590276.0 12:08:01
19 13712130 74.3 SELL 1583219.2 2408620.8 12:08:01
20 13712130 74.3 SELL 1583219.2 2408620.8 12:08:01
21 13715699 74.3 SELL 1583219.2 2408620.8 12:08:01
22 13720809 74.3 SELL 1583219.2 2408620.8 12:08:01
23 13726310 74.3 SELL 1583219.2 2408620.8 12:08:01
24 13726310 74.3 SELL 1583219.2 2408620.8 12:08:01
25 13726410 74.3 SELL 1583219.2 2408620.8 12:08:01
edited Nov 4 at 10:26
answered Nov 4 at 10:12
jezrael
303k20233309
303k20233309
1
Sir, Is it possible to select particular columns as I want to apply to last 4 columns only.
– Pravat
Nov 4 at 10:16
1
@Pravat - Super, glad can help! :)
– jezrael
Nov 4 at 10:32
add a comment |
1
Sir, Is it possible to select particular columns as I want to apply to last 4 columns only.
– Pravat
Nov 4 at 10:16
1
@Pravat - Super, glad can help! :)
– jezrael
Nov 4 at 10:32
1
1
Sir, Is it possible to select particular columns as I want to apply to last 4 columns only.
– Pravat
Nov 4 at 10:16
Sir, Is it possible to select particular columns as I want to apply to last 4 columns only.
– Pravat
Nov 4 at 10:16
1
1
@Pravat - Super, glad can help! :)
– jezrael
Nov 4 at 10:32
@Pravat - Super, glad can help! :)
– jezrael
Nov 4 at 10:32
add a comment |
up vote
1
down vote
You can use mask
+ ffill
:
values = df.iloc[:, -4:]
df.iloc[:, -4:] = values.mask(values.isin([0, '0'])).ffill()
add a comment |
up vote
1
down vote
You can use mask
+ ffill
:
values = df.iloc[:, -4:]
df.iloc[:, -4:] = values.mask(values.isin([0, '0'])).ffill()
add a comment |
up vote
1
down vote
up vote
1
down vote
You can use mask
+ ffill
:
values = df.iloc[:, -4:]
df.iloc[:, -4:] = values.mask(values.isin([0, '0'])).ffill()
You can use mask
+ ffill
:
values = df.iloc[:, -4:]
df.iloc[:, -4:] = values.mask(values.isin([0, '0'])).ffill()
answered Nov 4 at 10:28
jpp
78.8k184592
78.8k184592
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53139680%2fcopy-previous-row-values-when-current-value-is-0-zero%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password