Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Create a new DataFrame

Here you are going to create a new DataFrame called df_AdjVol.

This DataFrame is going to store the AdjVolume for each of IBM, Microsoft and Google.

You will use the pandas DataFrame() function to create the DataFrame and then add 3 new columns to it
with names 'IBM', Microsoft' and 'Google'.

You will use the data in the 'AdjVolume' columns from your previous DataFrames to populate your new
DataFrame.

In [ ]: df_Vol = pd.DataFrame()

df_Vol['IBM'] = df_IBM['Volume']

df_Vol['MSoft'] = df_MSFT['Volume']

df_Vol['Google'] = df_GOOGL['Volume']

df_Vol.head()

A 50,000 Foot view of a DataFrame


Quite often it's useful to get a quick mental image of the rows, columns, size and shape of a DataFrame.

Use the shape and size attributes.

shape returns the number of rows and columns


size returns the number of cells (rows * columns)

In addition, pandas supplies a useful function called describe() that prints out some summary information
about a DataFrame.

Finally, you can use the transpose() function on a DataFrame to flip the output around. Transposing a
DataFrame may or may not be useful depending on your personal preferences, size and shape of your data, etc.

Transposing after a describe() can often be useful

In [ ]: df_Vol.shape

df_Vol.size

df_Vol.describe()

df_Vol.describe().transpose()

df_Vol.transpose()

Filtering Data
Filters in a DataFrame allow you to conditionally select data from a DataFrame

These are very similar to filters in Excel.

syntax is

df[expr]

where expr is something that resolves to True or False

e.g.

You might also like