df = pd.read_csv(...)
df.pivot(columns='region', values='vdem_corr')
My solution is:
result = df.groupby('region').apply(lambda grp: pd.Series(
grp.vdem_corr.values)).unstack(level=1).T
The advantage over the answer by Prahken is that my result has much less NaN values.
Try on your own and compare.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.