Тёмный

Comparing values in Pandas with "diff" and "pct_change" 

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

Want to know how much the values in a series or data frame have changed from row to row? Meet the "diff" method, which will calculate this for you -- either from the previous row, or from any other row. And if you want to know the percentage change? Just use "pct_change" instead.

Наука

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

 

6 ноя 2023

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 4   
@AndyWallWasWeak
@AndyWallWasWeak 3 месяца назад
off topic Q, but inspired by a moment from this vid. When writing own functions, should I write for pd.Series or 1-column DataFrame? Sounds like could be multiple things to keep in mind when deciding
@ReuvenLerner
@ReuvenLerner 3 месяца назад
I'd suggest not writing anything for a 1-column data frame. Either write for a data frame (regardless of size), or for a series / column. I think that the latter is probably a better way to go, overall.
@tyl9680
@tyl9680 Месяц назад
What about diff by different categories? Say I have corn, rice, beans and wheat prices in the same df, and I want to compare the price changes within the same catogories.
@ReuvenLerner
@ReuvenLerner Месяц назад
You can totally do this! Just use "diff" on the result of a "groupby". For example: df = DataFrame({'category': ['wheat', 'corn', 'rice', 'wheat', 'corn', 'rice', 'wheat', 'corn', 'rice'], 'price': [10, 8, 6, 11, 7, 5, 15, 9, 4]}) df.groupby('category')[['price']].diff() You'll get a new data frame back (thanks to the double square brackets around 'price'), showing the difference for each row from the previous occurrence of that category. However, if you want to know which category is which, you'll probably want to join it back to the original data frame: df.groupby('category')[['price']].diff().join(df, rsuffix='_df')
Далее
Method chaining in Pandas
18:17
Просмотров 1,7 тыс.
My little bro is funny😁  @artur-boy
00:18
Просмотров 8 млн
Клип Уже На Канале #янгер #shorts
00:15
The six most important read_csv arguments in Pandas
16:50
LeetCode 330 : Patching Array | Easy Explanation
8:34
Просмотров 3,6 тыс.
When should I use a "groupby" in pandas?
8:25
Просмотров 242 тыс.
Boolean indexing in Pandas made simple
8:23
Просмотров 1,6 тыс.
3 PYTHON AUTOMATION PROJECTS FOR BEGINNERS
17:00
Просмотров 1,5 млн
UNDERSTANDING LOC[ ] & iLOC[ ] IN PANDAS
11:13
Просмотров 59 тыс.
Best mobile of all time💥🗿 [Troll Face]
0:24
Просмотров 719 тыс.