I am a first time python user. I have a text file of star data that I need to sort the columns and then just take the data from the V band. I have no idea how to start. Can someone please help even if it's to just get me started?
Asked
Active
Viewed 316 times
-3
-
2Yes of course we will help! But we can't unless you give us more details, make the effort of detailing the process, and try to write some code so we can help you fix it. – zoubida13 Jun 13 '16 at 15:35
-
Show use the file and the output you want... – Destrif Jun 13 '16 at 15:35
-
Ok I can try, I'm completely new to to this so it might be difficult. It's a large file with over 3000 data points, looks to be about 19 columns that aren't lined up properly (I think). The data are magnitudes taken with different filters, the filter I want information from is the V filter. – Torrance Jun 13 '16 at 15:38
-
Assuming that the file is not in HTML format, the coloums is most likely delimited with spaces, tabs, quotes and/or commas. We need to see some 10-15 lines of the data. – Jorgen Jun 13 '16 at 16:59
-
`JD Magnitude Uncertainty HQuncertainty Band Observer Code Comment Code(s) Comp Star 1 Comp Star 2 Charts Comments Transfomed Airmass Validation Flag Cmag Kmag HJD Star Name Observer Affiliation Measurement Method Grouping Method ADS Reference Digitizer Credit 2446354.1 12.0 Vis. KOA V RZ PSC STD 2446380.0 11.8 Vis. KOA V RZ PSC STD 2446405.0 11.8 Vis. KOA V RZ PSC STD 2446712.1 11.7 Vis. KOA V RZ PSC STD 2446718.0 11.7 Vis. KOA V RZ PSC STD 2446738.9 11.6 Vis. KOA V RZ PSC STD` – Torrance Jun 13 '16 at 17:08
1 Answers
0
If you can install Pandas from here then sorting on any column can be done like this:
#!/usr/bin/python
# read_stars.py
import sys
import pandas as pd
filename = sys.argv[1] # or 'star_data.txt'
sep = '\t' # or ',' or ' ', etc.
df = pd.read_csv(filename, sep)
print df.sort(['Band'])
Change the commented lines to better suit your needs. sep
from your comment seems the separator may be tabs (so first try '\t'
and change until parsing is successful).sys.argv[1]
uses the file passed as a command line argument as such:
$ python read_stars.py star_data.txt
JD Magnitude Uncertainty HQuncertainty Band Observer Code \
28 2.456420e+06 16.400 0.073 NaN V PSD
29 2.456421e+06 16.09 0.090 NaN V DKS
... (etc) ...
42 STD NaN NaN NaN
0 STD NaN NaN NaN
[58 rows x 23 columns]
Hope this helps!

Community
- 1
- 1

chickity china chinese chicken
- 7,709
- 2
- 20
- 49
-
when I enter this in I get this error `__main__:1: FutureWarning: sort(columns=....) is deprecated, use sort_values(by=.....)` – Torrance Jun 20 '16 at 18:43
-
That's true, sort(columns=....) is deprecated, change it to use sort_values(by=['Band']) – chickity china chinese chicken Jun 20 '16 at 19:24