Pandas commands ending with parentheses and those that do not
Pandas Parentheses

This introduction to pandas is derived from Data School's pandas Q&A with my own notes and code.

Pandas commands ending with parentheses and those that do not

In [1]:
import pandas as pd
In [2]:
url = 'http://bit.ly/imdbratings'
movies = pd.read_csv(url)
In [4]:
# Looking at the first 5 rows of the DataFrame
movies.head()
Out[4]:
star_rating title content_rating genre duration actors_list
0 9.3 The Shawshank Redemption R Crime 142 [u'Tim Robbins', u'Morgan Freeman', u'Bob Gunt...
1 9.2 The Godfather R Crime 175 [u'Marlon Brando', u'Al Pacino', u'James Caan']
2 9.1 The Godfather: Part II R Crime 200 [u'Al Pacino', u'Robert De Niro', u'Robert Duv...
3 9.0 The Dark Knight PG-13 Action 152 [u'Christian Bale', u'Heath Ledger', u'Aaron E...
4 8.9 Pulp Fiction R Crime 154 [u'John Travolta', u'Uma Thurman', u'Samuel L....
In [6]:
# This will show descriptive statistics of numeric columns
movies.describe()
Out[6]:
star_rating duration
count 979.000000 979.000000
mean 7.889785 120.979571
std 0.336069 26.218010
min 7.400000 64.000000
25% 7.600000 102.000000
50% 7.800000 117.000000
75% 8.100000 134.000000
max 9.300000 242.000000
In [14]:
movies.describe(include=['float64'])
Out[14]:
star_rating
count 979.000000
mean 7.889785
std 0.336069
min 7.400000
25% 7.600000
50% 7.800000
75% 8.100000
max 9.300000
In [7]:
# Finding out dimensionality of DataFrame
movies.shape
Out[7]:
(979, 6)
In [9]:
# Finding out data types of each columns
movies.dtypes
Out[9]:
star_rating       float64
title              object
content_rating     object
genre              object
duration            int64
actors_list        object
dtype: object
In [15]:
type(movies)
Out[15]:
pandas.core.frame.DataFrame

As a Data Frame, it has certain methods and attributes

  • Methods: with parentheses
    • Action-oriented
      • movies.head()
      • movies.describe()
    • Parentheses allows optional arguments
      • movies.describe(include='object')
  • Attributes: without parentheses
    • Description-oriented
      • movies.shape
      • movies.dtypes

Hit shift + tab multiple times to learn more about the parantheses

  • 1x for a pop-up
  • 2x for a larger pop-up
  • 4x for a split-screen
Tags: pandas