I need to rearrange/sort this massive data for my research

Basically this data is about 500000 x 300 right now.
500000 rows represent different points in a region of a park (rectangle, 250m apart), and they are specified by first two columns (X and Y point).
Then, the column goes from 2000 jan 1 to present day. The dates are 16 days apart, and each day the value of ndvi (how gree the field it) was measured for each 500000 point. Then the column goes again with how reliable the ndvi is (calling it the p-value), again from 2000 jan 1 to present.


So, what I'm trying to do is I want to rearrange the data so that, all the dates will be in 1 column, and ndvi/pvalue will be right next to it

RIGHT NOW

x y N20000101 N20000117 .... N20120505 P20000101 P20000117 ..... P20120505
1 1 .100 .200 .... .200 1 2 ..... 1
1 2 .110 .201 .... .233 0 2 ..... 1
.....


I WANT TO

x y Date NDVI P
1 1 20000101 .100 1
20000117 .200 2
.....
20120505 .200 1
1 2 20000101 .110 0
20000117 .201 2
.......


You get the idea. Please let me know if you have any idea of how to approach this. Thank you!