I am using 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]
Why if I do this a new row is added at the end of the dataset? A row with all NaN except 'X2 House Age'.... I'm must doing something wrong but I don't know why.
IIUC, if you want to assign the values from
pd.cuttoX2 house agecolumn, you can simply do:Prints: