pandas库的基本使用

pandas库的基本使用

发现自己从来都是丢给GPT而没写过类似的pandas,想开始试试kaggle的时候看到有相关教程,就记记笔记

import pandas as pd
file_path = 'xxx.csv'
data = pd.read_csv(file_path)  # 读取csv文件
data.describe()#打印全表

上面就是最基础的操作,如果想展示列的话

data.columns

如果想丢弃有缺失值的值的话

new_data = data.dropna(axis=0)#丢弃行
new_data = data.dropna(axis=1)#丢弃列

Dot notation, which we use to select the “prediction target” 我把这个理解为一种点标注,标注一个属性用来预测

y = melbourne_data.Price#选择melbourne_data的Price列作为预测目标

选择筛选对应的属性特征

melbourne_features = ['Rooms', 'Bathroom', 'Landsize', 'Lattitude', 'Longtitude']
X = melbourne_data[melbourne_features]
X.describe()



Enjoy Reading This Article?

Here are some more articles you might like to read next: