← Back to Pandas Course | Chapter 9: Reshaping Data | Lesson 5 of 6

Transpose करना

Transposing rows और columns को swap कर देता है, जैसे table को एक चौथाई घुमा देना।

In this page:

  1. Transposing
Syntax
python
transposed = df.T

Transposing

df.T rows और columns को पलट देता है, इसलिए index column headers बन जाता है। यह describe() जैसे wide summaries को देखने के लिए उपयोगी है। Transpose करने के बाद mixed dtypes object बन जाते हैं।

Note: df.describe().T को पढ़ना अक्सर आसान होता है।

उदाहरण: Transposing

python
import pandas as pd

df = pd.DataFrame({"a": [1, 2], "b": [3, 4]}, index=["r1", "r2"])
print(df.T)
print(df.describe().T[["mean", "max"]])

# Output:
#    r1  r2
# a   1   2
# b   3   4
#    mean  max
# a   1.5  2.0
# b   3.5  4.0
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. mixed data को transpose करने के बाद dtypes खो देना
  2. यह भूल जाना कि index columns बन जाता है
  3. बहुत बड़े tables को transpose करना
चैप्टर सारांश
  • .T rows और columns swap करता है
  • Index column headers बन जाता है
  • Mixed dtypes object बन जाते हैं
  • describe().T एक सुविधाजनक view है
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 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.