reshape a pandas dataframe
问题 suppose a dataframe like this one: df = pd.DataFrame([[1,2,3,4],[5,6,7,8],[9,10,11,12]], columns = ['A', 'B', 'A1', 'B1']) I would like to have a dataframe which looks like: what does not work: new_rows = int(df.shape[1]/2) * df.shape[0] new_cols = 2 df.values.reshape(new_rows, new_cols, order='F') of course I could loop over the data and make a new list of list but there must be a better way. Any ideas ? 回答1: The pd.wide_to_long function is built almost exactly for this situation, where you