pandas counts the number of rows and obtains field information examples

  • Count the number of rows in the data set and save the result as row_num
  • Get the name of each field of the data set, and save the result as col_array
  • From the data set, read the information of the fields school, sex, age, address, and save the result as data
import pandas as pd
all_data = pd.read_csv('studentmath.csv')

# 统计行数
row_num = len(all_data)

# 获取各字段名称
col_array = all_data.columns

# 读取指定字段信息
data = all_data[['school','sex','age','address']]

print(row_num )
print(col_array )
print(data )

Guess you like

Origin blog.csdn.net/weixin_44039266/article/details/106074214