Skip to main content

__ Back to top

__ ` Ctrl ` \+ ` K `

[ ![pandas 2.2.1 documentation - Home](../_static/pandas.svg) ](../index.html)

Site Navigation

  * [ Getting started ](../getting_started/index.html)
  * [ User Guide ](index.html)
  * [ API reference ](../reference/index.html)
  * [ Development ](../development/index.html)
  * [ Release notes ](../whatsnew/index.html)

  * [ __ GitHub  ](https://github.com/pandas-dev/pandas "GitHub")
  * [ __ Twitter  ](https://twitter.com/pandas_dev "Twitter")
  * [ __ Mastodon  ](https://fosstodon.org/@pandas_dev "Mastodon")

Site Navigation

  * [ Getting started ](../getting_started/index.html)
  * [ User Guide ](index.html)
  * [ API reference ](../reference/index.html)
  * [ Development ](../development/index.html)
  * [ Release notes ](../whatsnew/index.html)

  * [ __ GitHub  ](https://github.com/pandas-dev/pandas "GitHub")
  * [ __ Twitter  ](https://twitter.com/pandas_dev "Twitter")
  * [ __ Mastodon  ](https://fosstodon.org/@pandas_dev "Mastodon")

  * [ 10 minutes to pandas ](10min.html)
  * [ Intro to data structures ](dsintro.html)
  * Essential basic functionality 
  * [ IO tools (text, CSV, HDF5, â¦) ](io.html)
  * [ PyArrow Functionality ](pyarrow.html)
  * [ Indexing and selecting data ](indexing.html)
  * [ MultiIndex / advanced indexing ](advanced.html)
  * [ Copy-on-Write (CoW) ](copy_on_write.html)
  * [ Merge, join, concatenate and compare ](merging.html)
  * [ Reshaping and pivot tables ](reshaping.html)
  * [ Working with text data ](text.html)
  * [ Working with missing data ](missing_data.html)
  * [ Duplicate Labels ](duplicates.html)
  * [ Categorical data ](categorical.html)
  * [ Nullable integer data type ](integer_na.html)
  * [ Nullable Boolean data type ](boolean.html)
  * [ Chart visualization ](visualization.html)
  * [ Table Visualization ](style.html)
  * [ Group by: split-apply-combine ](groupby.html)
  * [ Windowing operations ](window.html)
  * [ Time series / date functionality ](timeseries.html)
  * [ Time deltas ](timedeltas.html)
  * [ Options and settings ](options.html)
  * [ Enhancing performance ](enhancingperf.html)
  * [ Scaling to large datasets ](scale.html)
  * [ Sparse data structures ](sparse.html)
  * [ Frequently Asked Questions (FAQ) ](gotchas.html)
  * [ Cookbook ](cookbook.html)

  * [ __ ](../index.html)
  * [ User Guide ](index.html)
  * Essential... 

#  Essential basic functionality  #

Here we discuss a lot of the essential functionality common to the pandas data
structures. To begin, letâs create some example objects like we did in the [
10 minutes to pandas  ](10min.html#min) section:

    
    
    In [1]: index = pd.date_range("1/1/2000", periods=8)
    
    In [2]: s = pd.Series(np.random.randn(5), index=["a", "b", "c", "d", "e"])
    
    In [3]: df = pd.DataFrame(np.random.randn(8, 3), index=index, columns=["A", "B", "C"])
    

##  Head and tail  #

To view a small sample of a Series or DataFrame object, use the [ ` head()  `
](../reference/api/pandas.DataFrame.head.html#pandas.DataFrame.head
"pandas.DataFrame.head") and [ ` tail()  `
](../reference/api/pandas.DataFrame.tail.html#pandas.DataFrame.tail
"pandas.DataFrame.tail") methods. The default number of elements to display is
five, but you may pass a custom number.

    
    
    In [4]: long_series = pd.Series(np.random.randn(1000))
    
    In [5]: long_series.head()
    Out[5]: 
    0   -1.157892
    1   -1.344312
    2    0.844885
    3    1.075770
    4   -0.109050
    dtype: float64
    
    In [6]: long_series.tail(3)
    Out[6]: 
    997   -0.289388
    998   -1.020544
    999    0.589993
    dtype: float64
    

##  Attributes and underlying data  #

pandas objects have a number of attributes enabling you to access the metadata

  * **shape** : gives the axis dimensions of the object, consistent with ndarray 

  * Axis labels 
    
    * **Series** : _index_ (only axis) 

    * **DataFrame** : _index_ (rows) and _columns_

Note, **these attrib