I'm having a lot of trouble importing a weirdly formatted text file into a Pandas DataFrame—or at all for that matter. Here are the first several lines of the text file:
Name RA Dec B vh sig Type D1 D2
00006-0211 000032.0 -021129 14.3 7323 31 4X 1.3 0.8
00006+2142 000035.6 214054 14.4 6605 32 5 P 1.0 0.7
N7814 000041.1 155203 12.0 1050 4 2A s 6.5 2.7
00010+2256 000101.2 225519 14.0 7301 34 5 1.9 1.0
N7816 000115.2 071203 14.0 5241 5 4 2.0 2.0
N7817 000124.9 202818 12.7 2309 5 4A 4.0 1.1
N7819 000150.3 311138 14.3 4953 10 3B s 2.0 1.8
N7820 000156.7 045513 13.9 3064 19 0 1.6 0.7
N7824 000232.2 063833 14.5 6134 28 2 1.9 1.3
0003+1955 000345.1 195527 14.0 7730 19 -6 0.3 0.3
N 1 000441.3 272550 13.4 4534 6 3A s 1.8 1.2
00056+2644 000535.3 264331 14.4 8741 36 3 1.0 .55
N 12 000610.9 042005 14.5 3941 4 4B R 2.0 1.7
I think the 'Name' column is really throwing everything off. I'm able to perfectly import the 'B' column on by using:
import pandas as pd
df1 = pd.read_fwf('cfa1.txt', skiprows=11, header=None, names['GARBAGE', 'B', 'vh', 'sig', 'Type', 'D1', 'D2'])
df2 = df1[['B', 'vh', 'sig', 'Type', 'D1', 'D2']]
df2.head()
where GARBAGE is all of the junk that isn't importing properly.
I've also tried:
df = pd.read_table('cfa1.txt', skiprows=11, header=None, names=['Name', 'RA', 'Dec', 'B', 'vh', 'sig', 'Type', 'D1', 'D2'])
df.head()
which didn't work. (I have many more failed attempts which I figure aren't worth including) Thank you in advance for your time and consideration!