回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我这里有一个csv文件<a href="http://www.exoplanet.eu/catalog/?f=%22radial%22+IN+detection+OR+%22astrometry%22+IN+detection+OR+%22transit%22+IN+detection">webpage</a>。
我想阅读下载文件中的一些列(csv版本可以在右上角下载)。</p>
<p>假设我想要两列:</p>
<ul>
<li>59在标题中是<code>star_name</code></li>
<li>60在标题中是<code>ra</code>。</li>
</ul>
<p>然而,由于某些原因,网页的作者有时决定移动列。</p>
<p>最后我想要这样的东西,记住价值观可能会丢失。</p>
<pre><code>data = #read data in a clever way
names = data['star_name']
ras = data['ra']
</code></pre>
<p>这将防止我的程序在以后再次更改列时出现故障,如果它们保持名称正确的话。</p>
<p>到目前为止,我已经尝试了各种使用<code>csv</code>模块和<code>pandas</code>模块的方法。两个都不走运。</p>
<p>编辑(添加了两行+我的数据文件头)。对不起,但是它非常长。)</p>
<pre><code># name, mass, mass_error_min, mass_error_max, radius, radius_error_min, radius_error_max, orbital_period, orbital_period_err_min, orbital_period_err_max, semi_major_axis, semi_major_axis_error_min, semi_major_axis_error_max, eccentricity, eccentricity_error_min, eccentricity_error_max, angular_distance, inclination, inclination_error_min, inclination_error_max, tzero_tr, tzero_tr_error_min, tzero_tr_error_max, tzero_tr_sec, tzero_tr_sec_error_min, tzero_tr_sec_error_max, lambda_angle, lambda_angle_error_min, lambda_angle_error_max, impact_parameter, impact_parameter_error_min, impact_parameter_error_max, tzero_vr, tzero_vr_error_min, tzero_vr_error_max, K, K_error_min, K_error_max, temp_calculated, temp_measured, hot_point_lon, albedo, albedo_error_min, albedo_error_max, log_g, publication_status, discovered, updated, omega, omega_error_min, omega_error_max, tperi, tperi_error_min, tperi_error_max, detection_type, mass_detection_type, radius_detection_type, alternate_names, molecules, star_name, ra, dec, mag_v, mag_i, mag_j, mag_h, mag_k, star_distance, star_metallicity, star_mass, star_radius, star_sp_type, star_age, star_teff, star_detected_disc, star_magnetic_field
11 Com b,19.4,1.5,1.5,,,,326.03,0.32,0.32,1.29,0.05,0.05,0.231,0.005,0.005,0.011664,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,2008,2011-12-23,94.8,1.5,1.5,2452899.6,1.6,1.6,Radial Velocity,,,,,11 Com,185.1791667,17.7927778,4.74,,,,,110.6,-0.35,2.7,19.0,G8 III,,4742.0,,
11 UMi b,10.5,2.47,2.47,,,,516.22,3.25,3.25,1.54,0.07,0.07,0.08,0.03,0.03,0.012887,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,2009,2009-08-13,117.63,21.06,21.06,2452861.05,2.06,2.06,Radial Velocity,,,,,11 UMi,229.275,71.8238889,5.02,,,,,119.5,0.04,1.8,24.08,K4III,1.56,4340.0,,
</code></pre>