import pandas as pd
print(f"{pd.show_versions()}\n")
data = [{"a": 1, "b": 2, "c": 3, "d": 4},
{"a": 5, "b": 6, "c": 7, "d": 8},
{"a": 9, "b": 10,"c": 11, "d": 12}]
df = pd.DataFrame(data)
df2 = df.iloc[:, -3:-1] # BUG: The last column - column '-1' is not printed.
print(f"{df2}\n") # (Only columns '-3', '-2' are printed).
#
# With this version of Pandas, all positive number
# slicings are working file.
#
# All negative number slicings are also working
# fine, EXCEPT for the last column of any
# dataframe - column '-1', which would NOT be
# printed.
Comment From: m-ganko
It is desired output. If you want to include last column, you need to use df.loc[:, -3:]
.
Python lists work the same way:
>>> l = [*range(5)]
>>> l[:-1]
[0, 1, 2, 3
Comment From: SHERMANCHEN08
Oh. Yes. Thank you very much for your reply!
On Sun, Mar 26, 2023 at 3:10 PM m-ganko @.***> wrote:
It is desired output. If you want to include last column, you need to use df.loc[:, -3:].
Python lists work the same way:
l = [*range(5)]>>> l[:-1] [0, 1, 2, 3
— Reply to this email directly, view it on GitHub https://github.com/pandas-dev/pandas/issues/52225#issuecomment-1484194487, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUIZS3LBICWFTHZNPLP45FDW6CPCPANCNFSM6AAAAAAWIJOLFU . You are receiving this because you authored the thread.Message ID: @.***>