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

后端 未结 9 2130
心在旅途
心在旅途 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 19:12

    df.info() function will give you result something like as below. If you are using read_csv method of Pandas without sep parameter or sep with ",".

    raw_data = pd.read_csv("a1:\aa2/aaa3/data.csv")
    raw_data.info()
    
    RangeIndex: 5144 entries, 0 to 5143
    Columns: 145 entries, R_fighter to R_age
    

提交回复
热议问题