header参数
read_csv读取时会自动识别表头,数据有表头时header不能设置为None, 默认读取第一行作为表头,即header=0;当数据没有表头时,第一行数据会被视为表头,应传入names参数设置表头名称或者设置header=None。
reset_index
将两个DataFrame拼接后,想要对拼接后的DataFrame重新设置索引要用reset_index 方法。
要想让之前的索引消失,传入参数:drop=True
修改一个对象时:
inplace=True:不创建新的对象,直接对原始对象进行修改;
inplace=False:对数据进行修改,创建并返回新的对象承载其修改结果
train_df = pd.read_csv('data\\train.csv', header=0)
test_df = pd.read_csv('data\\test.csv', header=0)
df = pd.concat([train_df, test_df])
df.reset_index(inplace=True)
网友评论