Тёмный

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

Python and Pandas with Reuven Lerner
Подписаться 19 тыс.
Просмотров 581
50% 1

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.

Наука

Опубликовано:

 

7 май 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 4   
@imothar
@imothar Месяц назад
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 Месяц назад
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 Месяц назад
How do i use np.NaN in a way that does NOT change ints to floats?
@ReuvenLerner
@ReuvenLerner Месяц назад
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
Просмотров 1,7 тыс.
He turned a baseball into a stylish shoe😱
00:59
Просмотров 622 тыс.
How To Create An Executable Python Program
3:48
Functions vs Classes: When to Use Which and Why?
10:49
Просмотров 144 тыс.
Pandas Where | pd.DataFrame.where()
5:09
Просмотров 6 тыс.
Boolean indexing in Pandas made simple
8:23
Просмотров 1,6 тыс.
Flipping Data with Pandas: Stack & Unstack
8:17
Просмотров 2,4 тыс.
JavaScript DESTRUCTURING in 8 minutes! 💥
8:41
Просмотров 13 тыс.
Asus  VivoBook Винда за 8 часов!
1:00
Просмотров 1,1 млн
Развод с OZON - ноутбук за 2875₽
17:48
iPhone 16 - КРУТЕЙШИЕ ИННОВАЦИИ
4:50