-2

I am trying to move some data in a pandas data frame.

I have this data now:

enter image description here

My expected behavior is:

enter image description here

So when col B = date/time the col B-E are shifted by one.

Gama11
  • 31,714
  • 9
  • 78
  • 100
  • Please read this guideline about asking good pandas questions: https://stackoverflow.com/a/20159305/1185138 I also recommend checking out the help centre https://stackoverflow.com/help – godfryd Jan 16 '19 at 17:21
  • 1
    It looks like your problem is caused by incorrectly reading/parsing an input file. Instead of shifting values between columns you should fix the root problem. Please post the code you are using for reading from the input file – godfryd Jan 16 '19 at 17:22
  • Welcome to Stack Overflow! Can you add the content of the pictures into your question on the site so that we can read it easier? This will allow more people to help. Also, can you include the code that you are using for this data frame? – Jack Moody Jan 16 '19 at 17:22

1 Answers1

0

You can try this:

df.loc[1:,'B':] = df.loc[1:,'B':].shift(1, axis=1).fillna(0)

Output:

   A    B           C    D    E
0  1    8  2011-06-01  ABC  ABC
1  2    0  2011-06-01  ABC  ABC
Scott Boston
  • 147,308
  • 15
  • 139
  • 187