← Back to Pandas Course | Chapter 10: Time Series | Lesson 5 of 7

shift/diff का उपयोग

shift values को ऊपर या नीचे ले जाता है और diff पिछली value घटाता है, दोनों समय के साथ बदलाव के लिए उपयोगी हैं।

In this page:

  1. shift/diff
Syntax
python
df["column"].shift(1)
df["column"].diff()

shift/diff

shift(1) data को एक row नीचे ले जाता है ताकि हर row पिछली value देख सके। diff() पिछली row से अंतर है और pct_change() percentage change देता है। Negative shift values आगे देखते हैं।

Note: pct_change, diff को पिछली value से divide करने के बराबर है।

उदाहरण: shift/diff

python
import pandas as pd

s = pd.Series([100, 110, 99, 120])
print(s.shift(1).tolist())
print(s.diff().tolist())
print(s.pct_change().round(3).tolist())

# Output:
# [nan, 100.0, 110.0, 99.0]
# [nan, 10.0, -11.0, 21.0]
# [nan, 0.1, -0.1, 0.212]
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह भूल जाना कि पहली row NaN बन जाती है
  2. गलत दिशा में shift करना
  3. unsorted data पर shift का उपयोग करना
चैप्टर सारांश
  • shift values को move करता है
  • diff change देता है
  • pct_change relative change देता है
  • पहली row NaN बन जाती है
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.