Search-and-replace Pandas values with "where" and "mask"

  Рет қаралды 471

Python and Pandas with Reuven Lerner

Python and Pandas with Reuven Lerner

28 күн бұрын

Want to replace some values, but not others, in your Pandas series or data frame? In this video, I introduce "where" and "mask", which help you accomplish this.

Пікірлер: 4
@imothar
@imothar 25 күн бұрын
Another great video👍 Just wondering if there were any specific reason why did not use pd.NA? Perhaps it's the same result in the end, when it comes to floats 🤷
@ReuvenLerner
@ReuvenLerner 25 күн бұрын
The future of Pandas is clearly pd.NA, and I should use it more! But in this particular case, it didn't make a difference: Using either np.nan or pd.NA will turn the dtype into floats. That's because the standard int type isn't nullable, meaning that it cannot handle pd.NA as anything other than a float. If, however, you were to set the dtype to be Int64 (note the capital), then using pd.NA would indeed do what you (and I) want.
@marcinpohl3264
@marcinpohl3264 26 күн бұрын
How do i use np.NaN in a way that does NOT change ints to floats?
@ReuvenLerner
@ReuvenLerner 26 күн бұрын
NaN is a float. So if you want to have NaN in an int column, then the ints will need to change to floats. HOWEVER, if you create your series with a nullable type, then you can use pd.NA instead of np.nan, and you'll be all set. That's because pd.NA is compatible with a wide variety of types: In [12]: s = Series([10, 20, 30, 40, 50]) In [13]: s.loc[3] = pd.NA In [14]: s Out[14]: 0 10.0 1 20.0 2 30.0 3 NaN 4 50.0 dtype: float64 In [15]: s = Series([10, 20, 30, 40, 50], dtype='Int64') In [16]: s.loc[3] = pd.NA In [17]: s Out[17]: 0 10 1 20 2 30 3 4 50 dtype: Int64
Method chaining in Pandas
18:17
Python and Pandas with Reuven Lerner
Рет қаралды 1,6 М.
*args and **kwargs - what are they, and how are they different?
10:42
Python and Pandas with Reuven Lerner
Рет қаралды 1,2 М.
КАХА и Джин 2
00:36
К-Media
Рет қаралды 4,1 МЛН
ХОТЯ БЫ КИНОДА 2 - официальный фильм
1:35:34
ХОТЯ БЫ В КИНО
Рет қаралды 2,6 МЛН
ONE MORE SUBSCRIBER FOR 6 MILLION!
00:38
Horror Skunx
Рет қаралды 14 МЛН
Understanding "with" and Python's context managers
14:00
Python and Pandas with Reuven Lerner
Рет қаралды 726
Flipping Data with Pandas: Stack & Unstack
8:17
Python and Pandas with Reuven Lerner
Рет қаралды 2,2 М.
What are the "nlargest" and "nsmallest" methods in Pandas? (And should you use them?)
8:06
Python and Pandas with Reuven Lerner
Рет қаралды 200
5 Tips To Write Better Python Functions
15:59
Indently
Рет қаралды 83 М.
5 Useful Dunder Methods In Python
16:10
Indently
Рет қаралды 50 М.
Selecting rows in Pandas using .loc and lambda
9:04
Python and Pandas with Reuven Lerner
Рет қаралды 771
Is THIS Python's MOST Underrated Operator? (Walrus Operator)
5:45
Five mistakes companies make teaching Python to their staff
8:45
Python and Pandas with Reuven Lerner
Рет қаралды 713
Эффект Карбонаро и бумажный телефон
1:01
История одного вокалиста
Рет қаралды 2,6 МЛН
POCO F6 PRO - ЛУЧШИЙ POCO НА ДАННЫЙ МОМЕНТ!
18:51
What’s your charging level??
0:14
Татьяна Дука
Рет қаралды 7 МЛН