dict से Series बनाना
एक dictionary एक Series बन जाती है जहाँ keys index हैं और values data हैं।
In this page:
Syntax
s = pd.Series({"label1": value1, "label2": value2})
Dict से Series
pd.Series को एक dict pass करना keys को index labels और values को data की तरह इस्तेमाल करता है, insertion order में। keys select या reorder करने के लिए एक index supply करें; missing keys NaN बन जाती हैं। यह labelled data model करने का एक natural तरीका है।
Note:
index की तरह keys की एक list pass करना सिर्फ वे keys चुनता है।
उदाहरण: Series from dict
import pandas as pd
ages = {"Ann": 28, "Bob": 35, "Cy": 41}
s = pd.Series(ages)
print(s)
print(pd.Series(ages, index=["Cy", "Ann", "Zed"]))
# Output:
# Ann 28
# Bob 35
# Cy 41
# dtype: int64
# Cy 41.0
# Ann 28.0
# Zed NaN
# dtype: float64
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. #}
आम गलतियां
- यह उम्मीद करना कि dict order sorted होगा
- dict में न होने वाली keys के साथ एक index pass करना और NaN भूल जाना
- Dictionary values को unhashable रखना
चैप्टर सारांश
- Keys index बन जाती हैं
- Values data बन जाती हैं
- एक custom index keys select करता है
- Missing keys NaN देती हैं
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: