Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mh0w/6a4af4494cae872dd44093782c9e9a86 to your computer and use it in GitHub Desktop.
Save mh0w/6a4af4494cae872dd44093782c9e9a86 to your computer and use it in GitHub Desktop.
pandas: dataframes: count rows or columns
import pandas as pd
df = pd.DataFrame(columns=['A','B','C','D','E','F','G'])
# rows
print(len(df.index)) # 0 - slightly faster in large dfs
print(df.shape[0]) # 0
# columns
print(len(df.columns)) # 7
print(df.shape[1]) # 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment