0
我想交換的兩個Python表中的行,如如何交換python(astropy.table)中兩個表的行?
In [15]: print t2
x y z
---- ---- ----
20.0 30.0 40.0
50.0 60.0 70.0
80.0 90.0 99.0
In [16]: print t1
a b c
--- --- ---
1.0 2.0 3.0
3.0 4.0 5.0
6.0 7.0 8.0
我想這是
In [15]: print t2
x y z
---- ---- ----
20.0 30.0 40.0
3.0 4.0 5.0
80.0 90.0 99.0
In [16]: print t1
a b c
--- --- ---
1.0 2.0 3.0
50.0 60.0 70.0
6.0 7.0 8.0
我試着用這裏Is there a standardized method to swap two variables in Python?給出的例子,但它們都沒有很可能工作由於行類型:
In [19]: type(t1[1])
Out[19]: astropy.table.row.Row
eg
In [20]: t1[1],t2[1] = t2[1], t1[1]
In [21]: print t1
a b c
---- ---- ----
1.0 2.0 3.0
50.0 60.0 70.0
6.0 7.0 8.0
In [22]: print t2
x y z
---- ---- ----
20.0 30.0 40.0
50.0 60.0 70.0
80.0 90.0 99.0
即t2沒有變化。有沒有修復它? 我也嘗試使用Python Simple Swap Function中給出的第一個解決方案,其中我將行更改爲列表並交換了它們,但它給出了斷言錯誤。有人可以幫忙嗎?