In the last lesson you saw that num pi arrays have a d type which is the type
of each element in the array.
For example the d type of this array is int64.
Int64 means a 64 bit integer.
Now this also applies to two dimensional arrays.
Each element in the array is expected to have the same type.
This can make it inconvenient to use unconventional num pi arrays to
represent the contents of a CSV file.
For example, suppose I tried to create a num pi array to represent the student
enrollment data from lesson one?
I've recreated a small piece of that data here.
Even though when I created the array, I entered integers and
volumes without quotes, each element has been converted to a string.
The dtype is also s14, meaning strings of length at most 14.
Obviously it doesn't make sense to take the mean of strings, such as cancelled,
but it would make sense to take the mean of just the days_to_cancel column.
The days_to_cancel column is column three, so I can access it like this.
However, if I take the mean of this column, then it doesn't work.
Instead, num pi says that it cannot perform the reduce with a flexible type,
which means that it doesn't know how to take the mean when not all of
the values are numbers.
That's one benefit of Panda's dataframes over two dimensional num pi arrays.
A dataframe is also a two dimensional data structure, but
each column is assumed to be a different type.
Another benefit is that dataframes have indexes similar to Panda's theories.
There is an index value for each row, and a name for column.
So instead, I'll create a Pandas DataFrame from this data.
I can do that by passing in a dictionary mapping column names
to lists of values for that column.
So, one key in the dictionary would be account_key, and
the list would be all of the values for the account_key column.
And similarly for the other columns.
Now when I take a look at the data frame, it's displayed in a nice table.
The column names are at the top and
the role indexes are integers starting at zero.
There are some other ways to creat Pandas data frames as well,
which you'll take a look at soon.
Now if I take the mean of the data frame,
it takes the mean of each numerical column and ignores the others.
It's udacity is a numerical column here with trues treated as one and
falses treated as zero.
You'll notice that Pandas did not take the mean of the entire data frame here,
but of each column.
Since each column is assumed to be a different type,
this makes more sense for Pandas.
You can also use the axis argument to take the mean of each row instead,
although that won't work in this case,
since each row contains some non-numerical data.