Transpose करना
Transposing rows और columns को swap कर देता है, जैसे table को एक चौथाई घुमा देना।
In this page:
Syntax
transposed = df.T
Transposing
df.T rows और columns को पलट देता है, इसलिए index column headers बन जाता है। यह describe() जैसे wide summaries को देखने के लिए उपयोगी है। Transpose करने के बाद mixed dtypes object बन जाते हैं।
Note:
df.describe().T को पढ़ना अक्सर आसान होता है।
उदाहरण: Transposing
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. #}
आम गलतियां
- mixed data को transpose करने के बाद dtypes खो देना
- यह भूल जाना कि index columns बन जाता है
- बहुत बड़े 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: