← Back to Pandas Course | Chapter 2: Series | Lesson 1 of 7

Series बनाना

एक Series एक list, एक dictionary, एक NumPy array, या एक single value से भी बन सकता है।

In this page:

  1. Series बनाना
Syntax
python
s = pd.Series(data, index=labels, name="series_name")

Series बनाना

pd.Series(data, index=..., name=...) एक Series बनाता है। Lists और arrays values supply करते हैं, जबकि एक scalar पूरे index में repeat होता है। name attribute Series को label करता है और एक DataFrame में रखे जाने पर column name बन जाता है।

Note: आप Series को एक name दे सकते हैं ताकि यह DataFrame headers में दिखे।

उदाहरण: Creating Series

python
import pandas as pd
import numpy as np

print(pd.Series([1, 2, 3]))
print(pd.Series(np.arange(3), index=list("abc"), name="values"))
print(pd.Series(7, index=["x", "y"]))

# Output:
# 0    1
# 1    2
# 2    3
# dtype: int64
# a    0
# b    1
# c    2
# Name: values, dtype: int64
# x    7
# y    7
# dtype: int64
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. एक index provide करना जिसकी length data से अलग हो
  2. name attribute भूल जाना
  3. बिना index के एक scalar pass करना
चैप्टर सारांश
  • pd.Series(data, index, name) syntax इस्तेमाल होता है
  • Scalars index पर broadcast होते हैं
  • Index length data से match होनी चाहिए
  • name Series को label करता है
🔒

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.