0
如何執行此操作?我有一個.csv文件下面的數據集:根據每個其他列的值合併大數據框
+------------+----------------+------------+---------------+------------+----------------+------------+----------------+------------+---------------+
| Date | NBDG LN Equity | Date | P2P LN Equity | Date | HWSL LN Equity | Date | BPCR LN Equity | Date | AXI LN Equity |
+------------+----------------+------------+---------------+------------+----------------+------------+----------------+------------+---------------+
| 09-08-2017 | 78,5 | 09-08-2017 | 877,061 | 09-08-2017 | 107,082 | 09-08-2017 | 1,0981 | 08-08-2017 | 94 |
| 08-08-2017 | 78,5 | 08-08-2017 | 878,7899 | 08-08-2017 | 106,5 | 08-08-2017 | 1,1021 | 07-08-2017 | 94 |
| 03-08-2017 | 78,5 | 07-08-2017 | 879,709 | 07-08-2017 | 106,2 | 07-08-2017 | 1,0945 | 02-08-2017 | 98,2472 |
| 01-08-2017 | 78,5 | 04-08-2017 | 879,6708 | 04-08-2017 | 105,4882 | 04-08-2017 | 1,0932 | 27-07-2017 | 98,5 |
+------------+----------------+------------+---------------+------------+----------------+------------+----------------+------------+---------------+
,我要「合併」成格式:
+------------+----------------+---------------+----------------+----------------+---------------+
| Date | NBDG LN Equity | P2P LN Equity | HWSL LN Equity | BPCR LN Equity | AXI LN Equity |
+------------+----------------+---------------+----------------+----------------+---------------+
| 09-08-2017 | 78,5 | 877,061 | 107,082 | 1,0981 | NA |
| 08-08-2017 | 78,5 | 878,7899 | 106,5 | 1,1021 | 94 |
| 07-08-2017 | NA | 879,709 | 106,2 | 1,0945 | 94 |
| 04-08-2017 | NA | 879,6708 | 105,4882 | 1,0932 | NA |
| 03-08-2017 | 78,5 | NA | NA | NA | NA |
| 02-08-2017 | NA | NA | NA | NA | 98,2472 |
| 01-08-2017 | 78,5 | NA | NA | NA | NA |
| 27-07-2017 | NA | NA | NA | NA | 98,5 |
+------------+----------------+---------------+----------------+----------------+---------------+
我怎麼能做到這一點沒有硬編碼太多了?我開始用
dfData = local_csv('Data.csv', timezone='DK', sep=';')
lDateColumns = [col for col in dfData.columns if 'Date' in col]
dfData[dfData[lDateColumns].apply(pd.Series.nunique, axis=1)==1]
,直到我注意到,有時指數相對於海誓山盟導致只有4行留下抵消唯一的行排序。
感謝
到目前爲止您嘗試過什麼?請發佈您的代碼。 – James