See also:

Learning Python, the Language

Pandas

Get column_nr in pandas/numpy.

if isinstance(X, pd.DataFrame):

X_is_df = True

row_nr = X.shape[0]

column_nr = X.shape[1]

if isinstance(X.columns, pd.core.index.MultiIndex):

df_columns_is_multi_index = True

else:

......