posD.head(15)
id | hour | labelPo | |
0 | 595941207920 | 0.0 | 27 |
1 | 595941207920 | 2.0 | 19 |
2 | 595941207920 | 4.0 | 22 |
3 | 595941207920 | 5.0 | 19 |
4 | 595941207920 | 6.0 | 21 |
5 | 595941207920 | 8.0 | 20 |
6 | 595941207920 | 10.0 | 32 |
7 | 595941207920 | 12.0 | 30 |
8 | 595941207920 | 14.0 | 35 |
9 | 595941207920 | 16.0 | 29 |
10 | 595941207920 | 18.0 | 33 |
11 | 595941207920 | 20.0 | 35 |
12 | 595941207920 | 22.0 | 27 |
13 | 901845022650 | 0.0 | 34 |
14 | 901845022650 | 2.0 | 34 |
pos_id_df = pd.DataFrame(list(set(pos.id)),columns=['id'])
for hour in range(0,24,2):
pos_id_df['hour_{}'.format(hour)] = pd.merge(pos_id_df,posD[posD['hour']==hour],how='left',on=['id'])['labelPo']
print(pos_id_df.shape)
pos_id_df.head()
id | hour_0 | hour_2 | hour_4 | hour_6 | hour_8 | hour_10 | hour_12 | hour_14 | hour_16 | hour_18 | hour_20 | hour_22 | |
0 | 5552670461657094 | 28.0 | 32.0 | 21.0 | 28.0 | 29.0 | 31.0 | 40.0 | 30.0 | 33.0 | 41.0 | 36.0 | 26.0 |
1 | 6752302227259400 | 49.0 | 52.0 | 50.0 | 53.0 | 55.0 | 51.0 | 53.0 | 45.0 | 54.0 | 55.0 | 47.0 | 48.0 |
2 | 9325181958357000 | 59.0 | 58.0 | 56.0 | 57.0 | 57.0 | 58.0 | 59.0 | 53.0 | 56.0 | 52.0 | 57.0 | 56.0 |
3 | 5317472485900300 | 49.0 | 45.0 | 51.0 | 50.0 | 51.0 | 48.0 | 44.0 | 44.0 | 41.0 | 51.0 | 44.0 | 43.0 |
4 | 6488655596355600 | 47.0 | 41.0 | 41.0 | 44.0 | 48.0 | 46.0 | 52.0 | 52.0 | 53.0 | 52.0 | 53.0 | 53.0 |
上面列名错位, id向右移动.