Peeking at data with head, tail, and describe

Intermediate Python for Finance

Kennedy Behrman

Data Engineer, Author, Founder

Understanding your data

  • Data is loaded correctly
  • Understand the data's shape
Intermediate Python for Finance

First look at data

aapl
Intermediate Python for Finance

First look at data

aapl
Date
03/27/2020
03/26/2020
03/25/2020
03/24/2020
Intermediate Python for Finance

First look at data

aapl
Price
Date
03/27/2020 247.74
03/26/2020 258.44
03/25/2020 245.52
03/24/2020 246.88
Intermediate Python for Finance

First look at data

aapl
Price Volume
Date
03/27/2020 247.74 51054150
03/26/2020 258.44 63140170
03/25/2020 245.52 75900510
03/24/2020 246.88 71882770
Intermediate Python for Finance

First look at data

aapl
Price Volume Trend
Date
03/27/2020 247.74 51054150 Down
03/26/2020 258.44 63140170 Up
03/25/2020 245.52 75900510 Down
03/24/2020 246.88 71882770 Up
Intermediate Python for Finance

Head

aapl.head()
             Price    Volumne    Trend
Date
03/27/2020   247.74   51054150   Down
03/26/2020   258.44   63140170   Up
03/25/2020   245.52   75900510   Down
03/24/2020   246.88   71882770   Up
03/23/2020   224.37   84188210   Down
Intermediate Python for Finance

Head

aapl.head()
Intermediate Python for Finance

Head

aapl.head(3)
```out
             Price    Volumne    Trend
Date
03/27/2020   247.74   51054150   Down
03/26/2020   258.44   63140170   Up
03/25/2020   245.52   75900510   Down
Intermediate Python for Finance

Tail

aapl.tail()
             Price    Volumne    Trend
Date
03/05/2020   292.92   46893220   Down
03/04/2020   302.74   54794570   Up
03/03/2020   289.32   79868850   Down
03/02/2020   298.81   85349340   Up
02/28/2020   273.36   106721200  Down
Intermediate Python for Finance

Describe

aapl.describe()
       Price        Volume
count  21.000000    2.100000e+01
mean   263.715714   7.551468e+07
std    23.360598    1.669757e+07
min    224.370000   4.689322e+07
25%    246.670000   6.409497e+07
50%    258.440000   7.505841e+07
75%    285.340000   8.418821e+07
max    302.740000   1.067212e+08
Intermediate Python for Finance

Include

aapl.describe(include='object')
        Trend
count   21
unique  2
top     Down
freq    14
Intermediate Python for Finance

Include

aapl.describe(include='all')
         Price       Volumne        Trend
count    21.000000   2.100000e+01   21
unique   NaN         NaN            2
top      NaN         NaN            Down
freq     NaN         NaN            14
mean     263.715714  7.551468e+07   NaN
std      23.360598   1.669757e+07   NaN
min      224.370000  4.689322e+07   NaN
25%      246.670000  6.409497e+07   NaN
Intermediate Python for Finance
aapl.describe(include=['float', 'object'])
       Price        Trend
count  21.000000    21
unique NaN          2
top    NaN          Down
freq   NaN          14
mean   263.715714   NaN
std    23.360598    NaN
min    224.370000   NaN
25%    246.670000   NaN
50%    258.440000   NaN
75%    285.340000   NaN
max    302.740000   NaN
Intermediate Python for Finance

Percentiles

aapl.describe(percentiles=[.1, .5, .9])
      Price       Volumne
count 21.000000   2.100000e+01
mean  263.715714  7.551468e+07
std   23.360598   1.669757e+07
min   224.370000  4.689322e+07
10%   242.210000  5.479457e+07
50%   258.440000  7.505841e+07
90%   292.920000  1.004233e+08
max   302.740000  1.067212e+08
Intermediate Python for Finance

Exclude

aapl.describe(exclude='float')
       Volumne        Trend
count  2.100000e+01   21
unique NaN            2
top    NaN            Down
freq   NaN            14
mean   7.551468e+07   NaN
std    1.669757e+07   NaN
min    4.689322e+07   NaN
25%    6.409497e+07   NaN
Intermediate Python for Finance

Let's practice!

Intermediate Python for Finance

Preparing Video For Download...