Open xstreck1 opened 3 days ago
Thanks for the report. This can be reproduced on just a Series.
ser = pd.Series({"a": 1, "b": 2})
%timeit row[["a", "b"]]
# 103 μs ± 273 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
%timeit row["a"], row["b"]
# 1.76 μs ± 12.4 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
I haven't checked, but likely looking up a single label has a fastpath, and requires less validation. Certainly any perf improvement is always welcome, but I'm not sure there is an issue here.
I presume the example in the OP is just a simplified version of the operation you're trying to perform. In any case, avoiding apply
at all costs is the best way to get good performance out of pandas.
Pandas version checks
[X] I have checked that this issue has not already been reported.
[X] I have confirmed this issue exists on the latest version of pandas.
[ ] I have confirmed this issue exists on the main branch of pandas.
Reproducible Example
The code below accesses two columns either together or separately:
Output:
Using
iloc
does not suffer the same issue. Replace:Output:
Installed Versions
Prior Performance
No response