how to create new dataframe columns from existing column

Solutions on MaxInterview for how to create new dataframe columns from existing column by the best coders in the world

showing results for - "how to create new dataframe columns from existing column"
Alexander
28 May 2017
1new_df = df.filter(like='n_') \
2           .replace(0., np.inf) \
3           .apply(lambda x: sorted(x), axis=1, result_type='expand') \
4           .replace(np.inf, 0.0)
5
6new_df.columns = ['new_1', 'new_2', 'new_3']
7
8out = pd.concat([df, new_df], axis=1)
9
similar questions