You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
>>> import pandas as pd
>>> s = pd.Series(index=range(2010, 2020))
>>> s.loc[2015:2010:-1] = [6, 5, 4, 3, 2, 1]
Traceback (most recent call last):
[...]
ValueError: cannot set using a slice indexer with a different length than the value
I see no reason why this shouldn't work, as setting with the forward slicer works without problems, and getting with the reverse slicer also works without issue:
>>> # turn list around because slicer is (not) reversed compared to above
>>> s.loc[2010:2015] = [6, 5, 4, 3, 2, 1][::-1]
>>> s
2010 1.0
2011 2.0
2012 3.0
2013 4.0
2014 5.0
2015 6.0
2016 NaN
2017 NaN
2018 NaN
2019 NaN
dtype: float64
>>> s.loc[2015:2010:-1] == [6, 5, 4, 3, 2, 1] # comparison, not assignment
2015 True
2014 True
2013 True
2012 True
2011 True
2010 True
dtype: bool
PS: For the failure, it does not matter if the RHS is a np.array, etc.
The text was updated successfully, but these errors were encountered:
On Thu, Aug 15, 2019 at 10:17 PM kmin-jeong ***@***.***> wrote:
can I try it?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#26939?email_source=notifications&email_token=AAKAOIVUYC6UPJGLYUEX65LQEYL3LA5CNFSM4HZIJBZKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4NRRUA#issuecomment-521869520>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAKAOIS7VDSD6W53V2S2X43QEYL3LANCNFSM4HZIJBZA>
.
Minimal example:
I see no reason why this shouldn't work, as setting with the forward slicer works without problems, and getting with the reverse slicer also works without issue:
PS: For the failure, it does not matter if the RHS is a np.array, etc.
The text was updated successfully, but these errors were encountered: