How do I retrieve the number of columns in a Pandas data frame?

后端 未结 9 2129
心在旅途
心在旅途 2021-01-29 18:06

How do you programmatically retrieve the number of columns in a pandas dataframe? I was hoping for something like:

df.num_columns
9条回答
  •  爱一瞬间的悲伤
    2021-01-29 18:50

    Like so:

    import pandas as pd
    df = pd.DataFrame({"pear": [1,2,3], "apple": [2,3,4], "orange": [3,4,5]})
    
    len(df.columns)
    3
    

提交回复
热议问题