使用Astropy转换Pandas柱
有一个pandas
数据框
_RAJ2000,_DEJ2000,RA_ICRS,DE_ICRS,mode,q_mode,class,SDSS12,m_SDSS12,ObsDate,Q,umag,e_umag,gmag,e_gmag,rmag,e_rmag,imag,e_imag,zmag,e_zmag,zsp,zph,e_zph,<zph>
02 59 43.85208,+00 14 50.0532,44.932717,0.247237,1,+,6,J025943.85+001450.0,*,2004.7267,3,25.252,0.709,24.427,0.377,22.923,0.186,22.844,0.255,22.173,0.505,,,,
02 59 43.18896,+00 14 49.9776,44.929954,0.247216,1,+,3,J025943.18+001449.9,,2004.7267,3,25.77,0.713,23.41,0.267,22.467,0.183,21.612,0.132,20.905,0.301,,0.5976,0.1462,0.5771
02 59 45.92184,+00 15 09.6372,44.941341,0.252677,1,+,3,J025945.92+001509.6,,2004.7267,3,23.707,1.067,22.886,0.219,21.501,0.105,21.026,0.104,20.984,0.423,,0.423,0.0924,0.4151
02 59 44.95968,+00 15 11.7252,44.937332,0.253257,1,+,3,J025944.95+001511.7,,2004.7267,3,22.729,0.546,24.475,0.791,21.847,0.152,21.244,0.137,21.931,0.96,,0.4073,0.1245,0.4036
02 59 42.50736,+00 15 01.6416,44.927114,0.250456,1,,3,J025942.50+001501.6,*,2004.7267,3,22.529,0.467,22.705,0.198,22.117,0.203,21.279,0.139,20.905,0.418,,0.7674,0.0744,0.7239
02 59 42.88320,+00 15 01.8144,44.92868,0.250504,1,,3,J025942.88+001501.8,*,2004.7267,3,24.755,0.864,23.219,0.168,22.533,0.14,22.161,0.152,22.508,0.602,,0.3329,0.1434,0.2613
02 59 41.84880,+00 15 05.7924,44.92437,0.251609,1,+,3,J025941.84+001505.7,*,2004.7267,3,22.849,0.377,23.707,0.279,22.378,0.141,21.274,0.082,20.76,0.221,,0.6223,0.0731,0.6115
02 59 46.54512,+00 15 10.8972,44.943938,0.253027,1,+,3,J025946.54+001510.8,*,2004.7267,3,22.34,0.372,21.589,0.074,20.139,0.033,19.577,0.031,19.066,0.081,,0.4006,0.0569,0.4019
02 59 45.76656,+00 15 34.6932,44.940694,0.259637,1,,3,J025945.76+001534.6,,2004.7267,3,25.362,0.977,22.829,0.169,22.873,0.266,23.286,0.543,21.734,0.601,,0.5175,0.1433,0.3604
我 在raj2000
和dej2000
列中。我应该能够使用Astropy
进行操作,但是如果我尝试第一个:
from astropy import units as u
from astropy.coordinates import SkyCoord
c = SkyCoord('23 58 36.30073', 'icrs', unit=(u.hourangle))
我得到
ValueError: Invalid character at col 0 in angle 'icrs'
我的问题是:
- 为什么我输入的字符串会导致错误,以及
- 如何应用<<代码> SkyCoord
PANDAS
列?
I have a pandas
dataframe that includes the columns _RA2000
and _DEJ2000
, thus:
_RAJ2000,_DEJ2000,RA_ICRS,DE_ICRS,mode,q_mode,class,SDSS12,m_SDSS12,ObsDate,Q,umag,e_umag,gmag,e_gmag,rmag,e_rmag,imag,e_imag,zmag,e_zmag,zsp,zph,e_zph,<zph>
02 59 43.85208,+00 14 50.0532,44.932717,0.247237,1,+,6,J025943.85+001450.0,*,2004.7267,3,25.252,0.709,24.427,0.377,22.923,0.186,22.844,0.255,22.173,0.505,,,,
02 59 43.18896,+00 14 49.9776,44.929954,0.247216,1,+,3,J025943.18+001449.9,,2004.7267,3,25.77,0.713,23.41,0.267,22.467,0.183,21.612,0.132,20.905,0.301,,0.5976,0.1462,0.5771
02 59 45.92184,+00 15 09.6372,44.941341,0.252677,1,+,3,J025945.92+001509.6,,2004.7267,3,23.707,1.067,22.886,0.219,21.501,0.105,21.026,0.104,20.984,0.423,,0.423,0.0924,0.4151
02 59 44.95968,+00 15 11.7252,44.937332,0.253257,1,+,3,J025944.95+001511.7,,2004.7267,3,22.729,0.546,24.475,0.791,21.847,0.152,21.244,0.137,21.931,0.96,,0.4073,0.1245,0.4036
02 59 42.50736,+00 15 01.6416,44.927114,0.250456,1,,3,J025942.50+001501.6,*,2004.7267,3,22.529,0.467,22.705,0.198,22.117,0.203,21.279,0.139,20.905,0.418,,0.7674,0.0744,0.7239
02 59 42.88320,+00 15 01.8144,44.92868,0.250504,1,,3,J025942.88+001501.8,*,2004.7267,3,24.755,0.864,23.219,0.168,22.533,0.14,22.161,0.152,22.508,0.602,,0.3329,0.1434,0.2613
02 59 41.84880,+00 15 05.7924,44.92437,0.251609,1,+,3,J025941.84+001505.7,*,2004.7267,3,22.849,0.377,23.707,0.279,22.378,0.141,21.274,0.082,20.76,0.221,,0.6223,0.0731,0.6115
02 59 46.54512,+00 15 10.8972,44.943938,0.253027,1,+,3,J025946.54+001510.8,*,2004.7267,3,22.34,0.372,21.589,0.074,20.139,0.033,19.577,0.031,19.066,0.081,,0.4006,0.0569,0.4019
02 59 45.76656,+00 15 34.6932,44.940694,0.259637,1,,3,J025945.76+001534.6,,2004.7267,3,25.362,0.977,22.829,0.169,22.873,0.266,23.286,0.543,21.734,0.601,,0.5175,0.1433,0.3604
and I'd like to convert them to degrees, as they appear in the RAJ2000
and DEJ2000
columns. I should be able to do it with astropy
, but if I try the first one:
from astropy import units as u
from astropy.coordinates import SkyCoord
c = SkyCoord('23 58 36.30073', 'icrs', unit=(u.hourangle))
I get
ValueError: Invalid character at col 0 in angle 'icrs'
So my questions are:
- why is the string I've inputted causing the error, and
- how can I apply
SkyCoord
to thepandas
columns?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要同时进行两个坐标的转换,并作为关键字参数提供框架:
结果:
You need to do the conversion for both coords simultaneously and supply the frame as a keyword argument:
Result:
如果您只想使用Astropy来解析坐标字符串
You can also do this using the
Angle
class if you just want to use astropy to parse the coordinate strings