简体   繁体   English

如何使用熊猫将每n行的行转置为列(python)?

[英]How to transpose rows to columns for every n rows with pandas (python)?

Please, supposing that I need to transpose a fixed subset of n rows, in this case 38, to columns. 请假设我需要将n行的固定子集(在这种情况下为38)转置为列。

How can I do without iterate every rows and without creating another dataframe? 如何在不迭代每一行且没有创建另一个数据帧的情况下怎么办?

d = {'2006-10-10 00:00:00': 0.0, '2006-10-10 01:00:00': 0.0, '2006-10-10 02:00:00': 0.0, '2006-10-10 03:00:00': 0.0, '2006-10-10 04:00:00': 0.0, '2006-10-10 05:00:00': 0.0, '2006-10-10 06:00:00': 0.0, '2006-10-10 07:00:00': 0.0, '2006-10-10 08:00:00': 0.0, '2006-10-10 09:00:00': 0.0, '2006-10-10 10:00:00': 0.0, '2006-10-10 11:00:00': 0.0, '2006-10-10 12:00:00': 0.0, '2006-10-10 13:00:00': 0.4, '2006-10-10 14:00:00': np.nan, '2006-10-10 15:00:00': np.nan, '2006-10-10 16:00:00': np.nan, '2006-10-10 17:00:00': np.nan, '2006-10-10 18:00:00': np.nan, '2006-10-10 19:00:00': np.nan, '2006-10-10 20:00:00': np.nan, '2006-10-10 21:00:00': np.nan, '2006-10-10 22:00:00': np.nan, '2006-10-10 23:00:00': np.nan, '2006-10-11 00:00:00': np.nan, '2006-10-11 01:00:00': np.nan, '2006-10-11 02:00:00': np.nan, '2006-10-11 03:00:00': np.nan, '2006-10-11 04:00:00': np.nan, '2006-10-11 05:00:00': np.nan, '2006-10-11 06:00:00': np.nan, '2006-10-11 07:00:00': np.nan, '2006-10-11 08:00:00': np.nan, '2006-10-11 09:00:00': np.nan, '2006-10-11 10:00:00': np.nan, '2006-10-11 11:00:00': np.nan, '2006-10-11 12:00:00': np.nan, '2006-10-11 13:00:00': np.nan, '2006-10-11 14:00:00': np.nan, '2006-10-11 15:00:00': np.nan, '2006-10-11 16:00:00': np.nan, '2006-10-11 17:00:00': np.nan, '2006-10-11 18:00:00': np.nan, '2006-10-11 19:00:00': np.nan, '2006-10-11 20:00:00': np.nan, '2006-10-11 21:00:00': np.nan, '2006-10-11 22:00:00': np.nan, '2006-10-11 23:00:00': np.nan, '2006-10-12 00:00:00': np.nan, '2006-10-12 01:00:00': np.nan, '2006-10-12 02:00:00': np.nan, '2006-10-12 03:00:00': np.nan, '2006-10-12 04:00:00': np.nan, '2006-10-12 05:00:00': np.nan, '2006-10-12 06:00:00': np.nan, '2006-10-12 07:00:00': np.nan, '2006-10-12 08:00:00': np.nan, '2006-10-12 09:00:00': np.nan, '2006-10-12 10:00:00': np.nan, '2006-10-12 11:00:00': np.nan, '2006-10-12 12:00:00': np.nan, '2006-10-12 13:00:00': np.nan, '2006-10-12 14:00:00': np.nan, '2006-10-12 15:00:00': np.nan, '2006-10-12 16:00:00': np.nan, '2006-10-12 17:00:00': np.nan, '2006-10-12 18:00:00': np.nan, '2006-10-12 19:00:00': np.nan, '2006-10-12 20:00:00': np.nan, '2006-10-12 21:00:00': np.nan, '2006-10-12 22:00:00': np.nan, '2006-10-12 23:00:00': np.nan, '2006-10-13 00:00:00': np.nan, '2006-10-13 01:00:00': np.nan, '2006-10-13 02:00:00': np.nan, '2006-10-13 03:00:00': np.nan, '2006-10-13 04:00:00': np.nan, '2006-10-13 05:00:00': 2.6, '2006-10-13 06:00:00': np.nan, '2006-10-13 07:00:00': np.nan, '2006-10-13 08:00:00': np.nan, '2006-10-13 09:00:00': np.nan, '2006-10-13 10:00:00': np.nan, '2006-10-13 11:00:00': np.nan, '2006-10-13 12:00:00': np.nan, '2006-10-13 13:00:00': np.nan, '2006-10-13 14:00:00': np.nan, '2006-10-13 15:00:00': np.nan, '2006-10-13 16:00:00': np.nan, '2006-10-13 17:00:00': np.nan, '2006-10-13 18:00:00': np.nan, '2006-10-13 19:00:00': 0.2, '2006-10-13 20:00:00': np.nan, '2006-10-13 21:00:00': np.nan, '2006-10-13 22:00:00': np.nan, '2006-10-13 23:00:00': np.nan, '2006-10-14 00:00:00': 0.2, '2006-10-14 01:00:00': np.nan, '2006-10-14 02:00:00': np.nan, '2006-10-14 03:00:00': np.nan, '2006-10-14 04:00:00': np.nan, '2006-10-14 05:00:00': np.nan, '2006-10-14 06:00:00': 0.2, '2006-10-14 07:00:00': np.nan, '2006-10-14 08:00:00': np.nan, '2006-10-14 09:00:00': np.nan, '2006-10-14 10:00:00': np.nan, '2006-10-14 11:00:00': np.nan, '2006-10-14 12:00:00': np.nan, '2006-10-14 13:00:00': np.nan, '2006-10-14 14:00:00': np.nan, '2006-10-14 15:00:00': np.nan, '2006-10-14 16:00:00': np.nan, '2006-10-14 17:00:00': np.nan, '2006-10-14 18:00:00': np.nan, '2006-10-14 19:00:00': 0.2, '2006-10-14 20:00:00': 3.0, '2006-10-14 21:00:00': np.nan, '2006-10-14 22:00:00': np.nan, '2006-10-14 23:00:00': np.nan, '2006-10-15 00:00:00': np.nan, '2006-10-15 01:00:00': 0.2, '2006-10-15 02:00:00': np.nan, '2006-10-15 03:00:00': np.nan, '2006-10-15 04:00:00': 0.8, '2006-10-15 05:00:00': np.nan, '2006-10-15 06:00:00': 8.6, '2006-10-15 07:00:00': 0.8, '2006-10-15 08:00:00': np.nan, '2006-10-15 09:00:00': np.nan, '2006-10-15 10:00:00': np.nan, '2006-10-15 11:00:00': np.nan, '2006-10-15 12:00:00': np.nan, '2006-10-15 13:00:00': np.nan, '2006-10-15 14:00:00': np.nan, '2006-10-15 15:00:00': np.nan, '2006-10-15 16:00:00': np.nan, '2006-10-15 17:00:00': np.nan, '2006-10-15 18:00:00': np.nan, '2006-10-15 19:00:00': np.nan, '2006-10-15 20:00:00': np.nan, '2006-10-15 21:00:00': np.nan, '2006-10-15 22:00:00': np.nan, '2006-10-15 23:00:00': np.nan, '2006-10-16 00:00:00': np.nan, '2006-10-16 01:00:00': np.nan, '2006-10-16 02:00:00': np.nan, '2006-10-16 03:00:00': np.nan, '2006-10-16 04:00:00': np.nan, '2006-10-16 05:00:00': np.nan, '2006-10-16 06:00:00': np.nan, '2006-10-16 07:00:00': np.nan, '2006-10-16 08:00:00': np.nan, '2006-10-16 09:00:00': np.nan, '2006-10-16 10:00:00': np.nan, '2006-10-16 11:00:00': np.nan, '2006-10-16 12:00:00': np.nan, '2006-10-16 13:00:00': np.nan, '2006-10-16 14:00:00': np.nan, '2006-10-16 15:00:00': np.nan, '2006-10-16 16:00:00': np.nan, '2006-10-16 17:00:00': np.nan, '2006-10-16 18:00:00': np.nan, '2006-10-16 19:00:00': np.nan, '2006-10-16 20:00:00': np.nan, '2006-10-16 21:00:00': np.nan, '2006-10-16 22:00:00': np.nan, '2006-10-16 23:00:00': np.nan, '2006-10-17 00:00:00': np.nan, '2006-10-17 01:00:00': np.nan, '2006-10-17 02:00:00': np.nan, '2006-10-17 03:00:00': np.nan, '2006-10-17 04:00:00': np.nan, '2006-10-17 05:00:00': np.nan, '2006-10-17 06:00:00': np.nan, '2006-10-17 07:00:00': np.nan, '2006-10-17 08:00:00': np.nan, '2006-10-17 09:00:00': np.nan, '2006-10-17 10:00:00': np.nan, '2006-10-17 11:00:00': np.nan, '2006-10-17 12:00:00': np.nan, '2006-10-17 13:00:00': np.nan, '2006-10-17 14:00:00': np.nan, '2006-10-17 15:00:00': np.nan, '2006-10-17 16:00:00': np.nan, '2006-10-17 17:00:00': np.nan, '2006-10-17 18:00:00': np.nan, '2006-10-17 19:00:00': np.nan, '2006-10-17 20:00:00': np.nan, '2006-10-17 21:00:00': 0.2, '2006-10-17 22:00:00': 25.4, '2006-10-17 23:00:00': np.nan, '2006-10-18 00:00:00': np.nan, '2006-10-18 01:00:00': np.nan, '2006-10-18 02:00:00': np.nan, '2006-10-18 03:00:00': 0.2, '2006-10-18 04:00:00': np.nan, '2006-10-18 05:00:00': np.nan, '2006-10-18 06:00:00': np.nan, '2006-10-18 07:00:00': np.nan, '2006-10-18 08:00:00': np.nan, '2006-10-18 09:00:00': np.nan, '2006-10-18 10:00:00': np.nan, '2006-10-18 11:00:00': np.nan, '2006-10-18 12:00:00': np.nan, '2006-10-18 13:00:00': np.nan, '2006-10-18 14:00:00': np.nan, '2006-10-18 15:00:00': np.nan, '2006-10-18 16:00:00': np.nan, '2006-10-18 17:00:00': np.nan, '2006-10-18 18:00:00': np.nan, '2006-10-18 19:00:00': np.nan, '2006-10-18 20:00:00': np.nan, '2006-10-18 21:00:00': np.nan, '2006-10-18 22:00:00': np.nan, '2006-10-18 23:00:00': np.nan, '2006-10-19 00:00:00': np.nan, '2006-10-19 01:00:00': np.nan, '2006-10-19 02:00:00': np.nan, '2006-10-19 03:00:00': np.nan, '2006-10-19 04:00:00': np.nan, '2006-10-19 05:00:00': np.nan, '2006-10-19 06:00:00': np.nan, '2006-10-19 07:00:00': np.nan, '2006-10-19 08:00:00': 0.8, '2006-10-19 09:00:00': 2.2, '2006-10-19 10:00:00': 3.6, '2006-10-19 11:00:00': 4.2, '2006-10-19 12:00:00': 3.0, '2006-10-19 13:00:00': 0.6, '2006-10-19 14:00:00': 0.2, '2006-10-19 15:00:00': 6.0, '2006-10-19 16:00:00': np.nan, '2006-10-19 17:00:00': 6.8, '2006-10-19 18:00:00': 6.4, '2006-10-19 19:00:00': 3.8, '2006-10-19 20:00:00': 0.4, '2006-10-19 21:00:00': np.nan, '2006-10-19 22:00:00': np.nan, '2006-10-19 23:00:00': np.nan, '2006-10-20 00:00:00': np.nan, '2006-10-20 01:00:00': np.nan, '2006-10-20 02:00:00': 0.2, '2006-10-20 03:00:00': np.nan, '2006-10-20 04:00:00': np.nan, '2006-10-20 05:00:00': np.nan, '2006-10-20 06:00:00': np.nan, '2006-10-20 07:00:00': np.nan, '2006-10-20 08:00:00': 0.6, '2006-10-20 09:00:00': np.nan, '2006-10-20 10:00:00': 0.2, '2006-10-20 11:00:00': np.nan, '2006-10-20 12:00:00': np.nan, '2006-10-20 13:00:00': np.nan, '2006-10-20 14:00:00': np.nan, '2006-10-20 15:00:00': np.nan, '2006-10-20 16:00:00': np.nan, '2006-10-20 17:00:00': np.nan, '2006-10-20 18:00:00': np.nan, '2006-10-20 19:00:00': np.nan, '2006-10-20 20:00:00': np.nan, '2006-10-20 21:00:00': np.nan, '2006-10-20 22:00:00': np.nan, '2006-10-20 23:00:00': np.nan, '2006-10-21 00:00:00': np.nan, '2006-10-21 01:00:00': np.nan, '2006-10-21 02:00:00': np.nan, '2006-10-21 03:00:00': np.nan, '2006-10-21 04:00:00': np.nan, '2006-10-21 05:00:00': np.nan, '2006-10-21 06:00:00': np.nan, '2006-10-21 07:00:00': np.nan, '2006-10-21 08:00:00': np.nan, '2006-10-21 09:00:00': np.nan, '2006-10-21 10:00:00': np.nan, '2006-10-21 11:00:00': np.nan, '2006-10-21 12:00:00': np.nan, '2006-10-21 13:00:00': np.nan, '2006-10-21 14:00:00': np.nan, '2006-10-21 15:00:00': np.nan, '2006-10-21 16:00:00': np.nan, '2006-10-21 17:00:00': np.nan, '2006-10-21 18:00:00': np.nan, '2006-10-21 19:00:00': np.nan, '2006-10-21 20:00:00': np.nan, '2006-10-21 21:00:00': np.nan, '2006-10-21 22:00:00': np.nan, '2006-10-21 23:00:00': np.nan, '2006-10-22 00:00:00': np.nan, '2006-10-22 01:00:00': np.nan, '2006-10-22 02:00:00': np.nan, '2006-10-22 03:00:00': np.nan, '2006-10-22 04:00:00': np.nan, '2006-10-22 05:00:00': np.nan, '2006-10-22 06:00:00': np.nan, '2006-10-22 07:00:00': np.nan, '2006-10-22 08:00:00': np.nan, '2006-10-22 09:00:00': np.nan, '2006-10-22 10:00:00': np.nan, '2006-10-22 11:00:00': np.nan, '2006-10-22 12:00:00': np.nan, '2006-10-22 13:00:00': np.nan, '2006-10-22 14:00:00': np.nan, '2006-10-22 15:00:00': np.nan, '2006-10-22 16:00:00': np.nan, '2006-10-22 17:00:00': np.nan, '2006-10-22 18:00:00': np.nan, '2006-10-22 19:00:00': np.nan, '2006-10-22 20:00:00': np.nan, '2006-10-22 21:00:00': np.nan, '2006-10-22 22:00:00': np.nan, '2006-10-22 23:00:00': np.nan, '2006-10-23 00:00:00': np.nan, '2006-10-23 01:00:00': np.nan, '2006-10-23 02:00:00': np.nan, '2006-10-23 03:00:00': np.nan, '2006-10-23 04:00:00': np.nan, '2006-10-23 05:00:00': np.nan, '2006-10-23 06:00:00': np.nan, '2006-10-23 07:00:00': 2.8, '2006-10-23 08:00:00': 1.4, '2006-10-23 09:00:00': np.nan, '2006-10-23 10:00:00': 3.2, '2006-10-23 11:00:00': 0.6, '2006-10-23 12:00:00': np.nan, '2006-10-23 13:00:00': np.nan, '2006-10-23 14:00:00': np.nan, '2006-10-23 15:00:00': np.nan, '2006-10-23 16:00:00': np.nan, '2006-10-23 17:00:00': np.nan, '2006-10-23 18:00:00': np.nan, '2006-10-23 19:00:00': np.nan, '2006-10-23 20:00:00': np.nan, '2006-10-23 21:00:00': np.nan, '2006-10-23 22:00:00': np.nan, '2006-10-23 23:00:00': np.nan, '2006-10-24 00:00:00': np.nan, '2006-10-24 01:00:00': np.nan, '2006-10-24 02:00:00': np.nan, '2006-10-24 03:00:00': np.nan, '2006-10-24 04:00:00': np.nan, '2006-10-24 05:00:00': np.nan, '2006-10-24 06:00:00': np.nan, '2006-10-24 07:00:00': np.nan, '2006-10-24 08:00:00': np.nan, '2006-10-24 09:00:00': np.nan, '2006-10-24 10:00:00': np.nan, '2006-10-24 11:00:00': np.nan, '2006-10-24 12:00:00': np.nan, '2006-10-24 13:00:00': np.nan, '2006-10-24 14:00:00': np.nan, '2006-10-24 15:00:00': np.nan, '2006-10-24 16:00:00': np.nan, '2006-10-24 17:00:00': np.nan, '2006-10-24 18:00:00': np.nan, '2006-10-24 19:00:00': np.nan, '2006-10-24 20:00:00': np.nan, '2006-10-24 21:00:00': np.nan, '2006-10-24 22:00:00': np.nan, '2006-10-24 23:00:00': np.nan, '2006-10-25 00:00:00': np.nan, '2006-10-25 01:00:00': np.nan, '2006-10-25 02:00:00': np.nan, '2006-10-25 03:00:00': np.nan, '2006-10-25 04:00:00': np.nan, '2006-10-25 05:00:00': np.nan, '2006-10-25 06:00:00': np.nan, '2006-10-25 07:00:00': np.nan, '2006-10-25 08:00:00': np.nan, '2006-10-25 09:00:00': np.nan, '2006-10-25 10:00:00': np.nan, '2006-10-25 11:00:00': np.nan, '2006-10-25 12:00:00': np.nan, '2006-10-25 13:00:00': np.nan, '2006-10-25 14:00:00': np.nan, '2006-10-25 15:00:00': np.nan, '2006-10-25 16:00:00': np.nan, '2006-10-25 17:00:00': np.nan, '2006-10-25 18:00:00': np.nan, '2006-10-25 19:00:00': np.nan, '2006-10-25 20:00:00': np.nan, '2006-10-25 21:00:00': np.nan, '2006-10-25 22:00:00': np.nan, '2006-10-25 23:00:00': np.nan, '2006-10-26 00:00:00': np.nan, '2006-10-26 01:00:00': np.nan, '2006-10-26 02:00:00': np.nan, '2006-10-26 03:00:00': np.nan, '2006-10-26 04:00:00': np.nan, '2006-10-26 05:00:00': np.nan, '2006-10-26 06:00:00': np.nan, '2006-10-26 07:00:00': np.nan, '2006-10-26 08:00:00': np.nan, '2006-10-26 09:00:00': np.nan, '2006-10-26 10:00:00': np.nan, '2006-10-26 11:00:00': np.nan, '2006-10-26 12:00:00': np.nan, '2006-10-26 13:00:00': np.nan, '2006-10-26 14:00:00': np.nan, '2006-10-26 15:00:00': np.nan, '2006-10-26 16:00:00': np.nan, '2006-10-26 17:00:00': np.nan, '2006-10-26 18:00:00': np.nan, '2006-10-26 19:00:00': np.nan, '2006-10-26 20:00:00': np.nan, '2006-10-26 21:00:00': np.nan, '2006-10-26 22:00:00': np.nan, '2006-10-26 23:00:00': np.nan, '2006-10-27 00:00:00': np.nan, '2006-10-27 01:00:00': np.nan, '2006-10-27 02:00:00': np.nan, '2006-10-27 03:00:00': np.nan, '2006-10-27 04:00:00': np.nan, '2006-10-27 05:00:00': np.nan, '2006-10-27 06:00:00': np.nan, '2006-10-27 07:00:00': np.nan, '2006-10-27 08:00:00': np.nan, '2006-10-27 09:00:00': np.nan, '2006-10-27 10:00:00': np.nan, '2006-10-27 11:00:00': np.nan, '2006-10-27 12:00:00': np.nan, '2006-10-27 13:00:00': np.nan, '2006-10-27 14:00:00': np.nan, '2006-10-27 15:00:00': np.nan, '2006-10-27 16:00:00': np.nan, '2006-10-27 17:00:00': np.nan, '2006-10-27 18:00:00': np.nan, '2006-10-27 19:00:00': np.nan, '2006-10-27 20:00:00': np.nan, '2006-10-27 21:00:00': np.nan, '2006-10-27 22:00:00': np.nan, '2006-10-27 23:00:00': np.nan, '2006-10-28 00:00:00': np.nan, '2006-10-28 01:00:00': np.nan, '2006-10-28 02:00:00': np.nan, '2006-10-28 03:00:00': np.nan, '2006-10-28 04:00:00': 4.0, '2006-10-28 05:00:00': np.nan, '2006-10-28 06:00:00': np.nan, '2006-10-28 07:00:00': np.nan, '2006-10-28 08:00:00': np.nan, '2006-10-28 09:00:00': np.nan, '2006-10-28 10:00:00': np.nan, '2006-10-28 11:00:00': 16.4, '2006-10-28 12:00:00': np.nan, '2006-10-28 13:00:00': 0.2, '2006-10-28 14:00:00': np.nan, '2006-10-28 15:00:00': np.nan, '2006-10-28 16:00:00': np.nan, '2006-10-28 17:00:00': np.nan, '2006-10-28 18:00:00': np.nan, '2006-10-28 19:00:00': np.nan, '2006-10-28 20:00:00': np.nan, '2006-10-28 21:00:00': np.nan, '2006-10-28 22:00:00': np.nan, '2006-10-28 23:00:00': np.nan, '2006-10-29 00:00:00': np.nan, '2006-10-29 01:00:00': np.nan, '2006-10-29 02:00:00': np.nan, '2006-10-29 03:00:00': np.nan, '2006-10-29 04:00:00': np.nan, '2006-10-29 05:00:00': np.nan, '2006-10-29 06:00:00': np.nan, '2006-10-29 07:00:00': np.nan, '2006-10-29 08:00:00': np.nan, '2006-10-29 09:00:00': np.nan, '2006-10-29 10:00:00': np.nan, '2006-10-29 11:00:00': np.nan, '2006-10-29 12:00:00': np.nan, '2006-10-29 13:00:00': np.nan, '2006-10-29 14:00:00': np.nan, '2006-10-29 15:00:00': np.nan, '2006-10-29 16:00:00': np.nan, '2006-10-29 17:00:00': np.nan, '2006-10-29 18:00:00': np.nan, '2006-10-29 19:00:00': np.nan, '2006-10-29 20:00:00': np.nan, '2006-10-29 21:00:00': np.nan, '2006-10-29 22:00:00': np.nan, '2006-10-29 23:00:00': np.nan, '2006-10-30 00:00:00': np.nan, '2006-10-30 01:00:00': np.nan, '2006-10-30 02:00:00': np.nan, '2006-10-30 03:00:00': np.nan, '2006-10-30 04:00:00': np.nan, '2006-10-30 05:00:00': np.nan, '2006-10-30 06:00:00': np.nan, '2006-10-30 07:00:00': np.nan, '2006-10-30 08:00:00': np.nan, '2006-10-30 09:00:00': np.nan, '2006-10-30 10:00:00': np.nan, '2006-10-30 11:00:00': np.nan, '2006-10-30 12:00:00': np.nan, '2006-10-30 13:00:00': np.nan, '2006-10-30 14:00:00': np.nan, '2006-10-30 15:00:00': np.nan, '2006-10-30 16:00:00': np.nan, '2006-10-30 17:00:00': np.nan, '2006-10-30 18:00:00': np.nan, '2006-10-30 19:00:00': np.nan, '2006-10-30 20:00:00': np.nan, '2006-10-30 21:00:00': np.nan, '2006-10-30 22:00:00': np.nan, '2006-10-30 23:00:00': np.nan, '2006-10-31 00:00:00': np.nan, '2006-10-31 01:00:00': np.nan, '2006-10-31 02:00:00': np.nan, '2006-10-31 03:00:00': np.nan, '2006-10-31 04:00:00': np.nan, '2006-10-31 05:00:00': np.nan, '2006-10-31 06:00:00': np.nan, '2006-10-31 07:00:00': np.nan, '2006-10-31 08:00:00': np.nan, '2006-10-31 09:00:00': np.nan, '2006-10-31 10:00:00': np.nan, '2006-10-31 11:00:00': np.nan, '2006-10-31 12:00:00': np.nan, '2006-10-31 13:00:00': np.nan, '2006-10-31 14:00:00': np.nan, '2006-10-31 15:00:00': np.nan, '2006-10-31 16:00:00': np.nan, '2006-10-31 17:00:00': np.nan, '2006-10-31 18:00:00': np.nan, '2006-10-31 19:00:00': np.nan, '2006-10-31 20:00:00': np.nan, '2006-10-31 21:00:00': np.nan, '2006-10-31 22:00:00': np.nan, '2006-10-31 23:00:00': np.nan, '2006-11-01 00:00:00': np.nan, '2006-11-01 01:00:00': np.nan, '2006-11-01 02:00:00': np.nan, '2006-11-01 03:00:00': np.nan, '2006-11-01 04:00:00': np.nan, '2006-11-01 05:00:00': np.nan, '2006-11-01 06:00:00': np.nan, '2006-11-01 07:00:00': np.nan, '2006-11-01 08:00:00': np.nan, '2006-11-01 09:00:00': np.nan, '2006-11-01 10:00:00': np.nan, '2006-11-01 11:00:00': np.nan, '2006-11-01 12:00:00': np.nan, '2006-11-01 13:00:00': np.nan}

df = pd.DataFrame.from_dict(d,orient='index')
df.index = pd.to_datetime(df.index)

columns = list(range(1,38+1))
df_ = pd.DataFrame(index=df.index, columns=columns)
df_ = df_.fillna(0)

i = 0
for index, row in ddf.iterrows():
    print(i, values.shape)
    values = ddf[i:i+38].T.values
    if values.shape[1]==38:
        df_.loc[index] = values.reshape(38) 
    i+=1

I was thinking about pivot , but I could reshaping the data. 我当时在考虑数据透视 ,但是我可以重塑数据。

You can't transpose a dataframe unless it has the same type of object in every column. 除非在每一列中都有相同类型的对象,否则您无法转置该数据框。 I would convert to numpy array for a transpose function if the data types are the same. 如果数据类型相同,我将转换为转置函数的numpy数组。

import numpy as np

df_t = np.transpose(df.to_numpy())

or... (the non-numpy solution) 或...(非numpy解决方案)

df_t = list(zip(*(df.to_numpy().to_list())))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM