1

Let's say I've a df

           value
2023-02-01     a
2023-02-02     b
2023-02-03     c
2023-02-04     d

when I try to reverse df and after doing some operations If i reverse back It not showing complete df Like

import pandas as pd
df = pd.DataFrame(
    {"value": {0: "a", 1: "b", 2: "c", 3: "d"}}
)
df.index = pd.date_range(start='2023-02-01', periods=4,freq='D')
new  = df.loc[::-1] #Reversing 1 time
new2 = new.loc[::-1] # Reversing back again..
print(new2)

Giving me # even though I haven't done any operations on df

2023-02-04     d

Expected

          value
2023-02-01     a
2023-02-02     b
2023-02-03     c
2023-02-04     d

Version Detials

Pandas 1.3.5
Python 3.9
  • 1
    What is your pandas version? for me working correctly. If change `loc` to `iloc` it working for you? – jezrael Feb 06 '23 at 07:43
  • Try ```df = pd.DataFrame( {"value": {0: "a", 1: "b", 2: "c", 3: "d"}} ) df.index = pd.date_range(start='2023-02-01', periods=4,freq='D') new = df.loc[::-1] df = new.loc[::-1] print(df)``` – idk Feb 06 '23 at 07:46
  • Wow `iloc` working @jezrael .. Can I know why? – Bhargav - Retarded Skills Feb 06 '23 at 07:46
  • [loc vs iloc](https://stackoverflow.com/questions/31593201/how-are-iloc-and-loc-different#:~:text=The%20main%20distinction%20between%20the,or%20columns)%20at%20integer%20locations.) – NIKUNJ PATEL Feb 06 '23 at 07:54
  • 1
    Just my 2 cents. I am getting the same problem (pandas '1.4.3'). iloc works for me, also reset_index before second reverse works too. – Yaroslav Fyodorov Feb 06 '23 at 07:55

0 Answers0