我用的是this csv
import pandas as pd
import numpy as np
real_estate = pd.read_csv('real_estate.csv',index_col=0)
buckets = pd.cut(real_estate['X2 house age'],4,labels=False).to_numpy()
for i in range(len(real_estate['X2 house age'])):
real_estate.loc[i,'X2 house age'] = buckets[i]
如果我这样做,为什么在数据集的末尾添加一个新行?一行,除了“X2 House”之外,所有NaN。我一定是做错了什么,但我不知道为什么。
1条答案
按热度按时间8zzbczxx1#
IIUC,如果你想把
pd.cut
列的值赋给X2 house age
列,你可以简单地做:图纸: