Dataframe读取行读取列

import numpy as np
import pandas as pd

df = pd.read_csv(r"D:\OCdata\ObesityDataSet_raw_and_data_sinthetic.csv")
# # -------按列读取
# print(df["Gender"])
# print(df[["Gender","Age"]])
# print(df.loc[:,"Age"])
# print(df.loc[:,["Gender","Age"]])
#
# # -------按行读取
# print(df.loc[3])
# print(df.loc[:3])
# print(df.loc[[1,2,3]])
# # -------行列一起用
# print(df.loc[0:3, "Age"])
# print(df.loc[0:3,["Age","Gender"]])
#
# # -------按照匹配条件提取多行
# print(df[df["Gender"] == "Male"])

你可能感兴趣的:(Python学习,python)