Timeline for answer to Using replace efficiently in pandas by EdChum
Current License: CC BY-SA 3.0
Post Revisions
9 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 15, 2023 at 2:10 | comment | added | jshibby | While this answer is clearly correct and interesting, it is a little odd to focus on timings after eliminating the loop - which was clearly the problem for speed. The other differences between map and replace will almost certainly be more important than the speed, which will likely be tiny even on a large set. | |
| Feb 9, 2021 at 8:53 | comment | added | haneulkim | Thanks!! Why is that the case? | |
| Feb 2, 2017 at 22:42 | vote | accept | splinter | ||
| Feb 2, 2017 at 21:54 | comment | added | EdChum | @root yes I can imagine that here only looking up 3 values repeatedly would be quicker than using a significantly larger dict | |
| Feb 2, 2017 at 21:51 | comment | added | root | Hmmm...I guess it depends on the size of the dictionary and values to be looked up. See the question I listed as a duplicate. | |
| Feb 2, 2017 at 21:50 | comment | added | EdChum |
@root I don't observe that: In [15]: %timeit df['1st'].map(idxDict) %timeit df['1st'].map(idxDict.get) %timeit df['1st'].map(idxDict) 100 loops, best of 3: 8.38 ms per loop 100 loops, best of 3: 4.22 ms per loop passing just the dict is 2x faster
|
|
| Feb 2, 2017 at 21:48 | comment | added | root |
df['1st'].map(idxDict.get) is actually faster than just passing the dictionary itself.
|
|
| Feb 2, 2017 at 21:24 | history | edited | EdChum | CC BY-SA 3.0 |
added 494 characters in body
|
| Feb 2, 2017 at 21:11 | history | answered | EdChum | CC BY-SA 3.0 |