Pastebin
API
tools
faq
paste
Login
Sign up
SHARE
TWEET
Pandas label column based on one condition
DECROMAX
Feb 24th, 2024
949
0
Never
Add comment
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!
Python
0.17 KB
| None
|
0
0
raw
download
clone
embed
print
report
# Pandas label column based on one condition
df
[
'new_column'
]
=
np.
where
(
(
df
[
'target_column'
]
==
'condition'
)
,
'Foo'
,
'Bar'
)
# if `Foo` first val, else `Bar` second value
Tags:
pandas numpy
Advertisement
Add Comment
Please,
Sign In
to add comment
Public Pastes
✅ Changelly Hacked
CSS | 8 min ago | 0.67 KB
AI destroys crypto
CSS | 8 min ago | 0.67 KB
✅ +12,000$ in 2 days
CSS | 9 min ago | 0.86 KB
✅ FREE COINS METHOD
CSS | 11 min ago | 0.67 KB
Got $12,000 from this method
CSS | 11 min ago | 0.67 KB
✅ 0 DAY Hacked
CSS | 12 min ago | 0.86 KB
Instant Profits Method
CSS | 17 min ago | 0.67 KB
+12,000$ in 2 days
CSS | 17 min ago | 0.67 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!