Thursday, 30 March 2017

Cannot reiindex in python

all_data = pd.concat((train.loc[:,'MSSubClass':'SaleCondition'], test.loc[:,'MSSubClass':'SaleCondition']),ignore_index=True)

Just add ",ignore_index=True" at the end. This should solve the issue

Monday, 27 March 2017

How to replace one column with the median values of the other column by grouping in python

X.loc[X.LotFrontage.isnull(), 'LotFrontage'] = X.groupby('Neighborhood').LotFrontage.transform('median')

X = the dataset name
LotFrontage = The column that has NA's
Neighborhood = The column that is to be used for grouping
median = can be replaced by mean etc...