-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DateTimeIndex values are assigned across entire df when using .loc #9478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is kind of tricky. You are assigning possibly a single value (or maybe a list, depends on what A is). with a list-like, IOW, and index (regardless of the value of A, it may have 0 or more elements). So I would say this is not really safe to do
Here is a better/safe way to do this.
|
OK but is there a reason why the datetimeindex behaves differently to when it's just an ordinary column of datetime64 dtype? For instance after df creation you then did |
@alan-wong what you are posting is not the same thing. you are assigning with an aligned series. this makes all the difference. The purpose of the index is to align things. When you use
I'll mark this as a bug, it seems the index (on the rhs) is not being treated as list-like, and instead maybe its trying to align. |
OK I see the semantic difference but just to point out that you don't observe this behaviour if the index is int64 : |
@alan-wong ok, fixed up in master. |
Cheers Jeff, sterling work as always |
I posted a 2-part answer to this question on SO: http://stackoverflow.com/questions/28482553/pandas-set-value-of-column-to-value-of-index-based-on-condtion
What I noticed is that if your index is a datetimeindex then assigning the values is not respecting the column selection and is blatting all rows.
I am using pandas 0.15.2 using numpy 1.9.1 and python 3.4 64-bit
example:
If the index is an Int64 type then this doesn't happen.
If you reset the index and then assign the values using .loc then it works correctly
The text was updated successfully, but these errors were encountered: