DESCRIBING A PANDAS DATAFRAME
Listing B.2 shows the content of pandas_df_describe.py, which illustrates how to define a Pandas DataFrame that contains a 3x3 NumPy array of integer values, where the rows and columns of the data frame are labeled. Other aspects of the data frame are also displayed.
Listing B.2: pandas_df_describe.py
import numpy as np
import pandas as pd
myarray = np.array([[10,30,20],
[50,40,60],[1000,2000,3000]])
rownames = ['apples', 'oranges', 'beer']
colnames = ['January', 'February', 'March']
mydf = pd.Data frame(myarray, index=rownames,
columns=colnames)
print("contents of df:")
print(mydf)
print()
print("contents of January:")
print(mydf['January'])
print()
print("Number of Rows:")
print(mydf.shape[0])
print()
print("Number of Columns:")
print(mydf.shape[1])
print()
print("Number of Rows and Columns:")
print(mydf.shape)
print()
print("...