import numpy as npimport pandas as pdimport perfplot
perfplot.save("out.png",setup=lambda n: pd.DataFrame(np.arange(n * 3).reshape(n, 3)),n_range=[2**k for k in range(25)],kernels=[lambda df: len(df.index),lambda df: df.shape[0],lambda df: df[df.columns[0]].count(),],labels=["len(df.index)", "df.shape[0]", "df[df.columns[0]].count()"],xlabel="Number of rows",)
len(df.columns)## Here:# df is your data.frame# df.columns returns a string. It contains column's titles of the df.# Then, "len()" gets the length of it.
df.shape??Type: propertyString form: <property object at 0x1127b33c0>Source:# df.shape.fget@propertydef shape(self):"""Return a tuple representing the dimensionality of the DataFrame."""return len(self.index), len(self.columns)
在Len的引擎盖下(df)
df.__len__??Signature: df.__len__()Source:def __len__(self):"""Returns length of info axis, but here we use the index """return len(self.index)File: ~/miniconda2/lib/python2.7/site-packages/pandas/core/frame.pyType: instancemethod
df = pd.DataFrame({'A': list('aabbc'), 'B': ['x', 'x', np.nan, 'x', np.nan]})s = df['B'].copy()
df
A B0 a x1 a x2 b NaN3 b x4 c NaN
s
0 x1 x2 NaN3 x4 NaNName: B, dtype: object
#import the data frame. Extention could be different as csv,xlsx or etc.data_fr = pd.read_csv('data.csv')
#print the number of rowsnu_rows = data_fr.shape[0]print(nu_rows)