BUG: Unexpected behavior using loc to assign value in a for loop
See original GitHub issuePandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas
# multiple assignement using index loc like code below (column name may vary)
for ... in ...:
[...]
indx_measure_started = df_meas[df_meas.key == something].index
df_meas.loc[indx_measure_started, "Vitesse Traverse"] = numpy.hstack(([0], numpy.abs(delta_position / delta_t)))
Issue Description
I don’t know why but there is a strange behavior after multiple use of loc for assignement. I’m sorry to not be able to give you a more precise way to reproduce… I tried to debug each line and don’t understand what is happening (may be something in the indexing.py file)
Using a setting value method like
df_meas.loc[indx_measure_started, "Vitesse Traverse"] = numpy.hstack(([0], numpy.abs(delta_position / delta_t)))
I can no more access the value using loc. Note that in the image below if I use loc + iloc I find the computed values…
Is it a kind of memory leaks ?
Expected Behavior
I expect to have the values readable…
TIPS :
- Behaviour as expected with 1.2.5, 1.3.5
- KO for 1.4.0
Installed Versions
Replace this line with the output of 1.4.3
Issue Analytics
- State:
- Created a year ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Unexpected behavior in Pandas indexing with .loc
I have a pandas data frame, called data, that has datetime indices. When I attempt to index the data by multiple datetimes, an...
Read more >Python – Pandas Dataframe using .loc for assignment gives ...
I am doing some calculations in pandas and the .loc method is having unexpected results. not sure if it is me misusing the...
Read more >Unexpected behavior (suspected bug) when using Mata views with ...
I encountered a very strange behavior when I use Mata views on temporary variables created by fvrevar. I tried to keep the following...
Read more >SettingwithCopyWarning: How to Fix This Warning in Pandas
It's no surprise that many struggle with this; there are so many ways to ... Setting the new value data.loc[data.bidder == 'parakeet2004', ...
Read more >A Python Beginner's Look at .loc. As a ... - Towards Data Science
As a Python beginner, using .loc to retrieve and update values in a pandas ... Passing just a column label or a blank...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Will close then, please ping to reopen if you have a reproducible example
@jultou-raa if you have a reproducible example you can ping to reopen as was stated above