I'm having some trouble reading some csv data into a pandas data frame. Here's what my data looks like:
C1, C2, C3, C4, C5,
5.0010254, 12, 0.37, 1.2672, 2039.5,
5.0499756, 12, 0.37, 1.2672, 2039.5,
5.1000244, 12, 0.37, 1.2672, 2039.5,
5.1500122, 12, 0.37, 1.2672, 2039.5,
5.2, 12, 0.37, 1.2672, 2039.5,
5.2499878, 12, 0.37, 1.2672, 2039.5,
5.2999756, 12, 0.37, 1.2672, 2039.5,
5.3500244, 12, 0.37, 1.2672, 2039.5,
5.4000122, 12, 0.37, 1.2672, 2039.5,
5.45, 12, 0.37, 1.2672, 2039.5,
5.4999878, 12, 0.37, 1.2672, 2039.5,
As you can see, the data is comma delimited, but also has a lot of spaces in it after the comma's. I do not know if this is what is causing me trouble, but if I say:
infl = pd.read_csv('filename.txt', sep=",", header=1, na_values=["-999"])
print infl['C2']
I get the error:
KeyError: 'C2'
I have tried the read_csv command with and without explicitly defining the delimiter without success. Any help is appreciated!
', +'? You could also look atread_fwfif your file is in fixed-width format (each column of data has a fixed width in characters).infl = pd.read_csv('filename.txt', sep=",\s+", header=1, na_values=["-999"])this will leave you with a trailing comma for your last column which you can remove later