I'm trying to read a fixed-width file into Python using Pandas but the first two columns are returned as one.
Here is a sample of the file I am trying to read in:
Some header information
Date day value
01/01/2015 000001 3.14
01/02/2015 2 1.59
and here is my code:
import pandas as pd
my_data = pd.read_fwf(my_file, skiprows=1)
but upon inspection of my_data
the first two columns are not separated:
> my_data.keys()
array(['Date day', 'value'])
I know that my columns all have a width of 15 characters -- however I have several files with different numbers of columns and the widths
option seems to expect a known number of columns (e.g. [(0, 15), (16, 30), ...]
) rather an being able to specify the widths but not the number of columns.
Does anyone know how to get pandas to recognize the first two columns are distinct?