I use pandas.read_fwf()
function in Python pandas 0.19.2 to read a file fwf.txt
that has the following content:
# Column1 Column2
123 abc
456 def
#
#
My code is the following:
import pandas as pd
file_path = "fwf.txt"
widths = [len("# Column1"), len(" Column2")]
names = ["Column1", "Column2"]
data = pd.read_fwf(filepath_or_buffer=file_path, widths=widths,
names=names, skip_blank_lines=True, comment="#")
The printed dataframe is like this:
Column1 Column2
0 123.0 abc
1 NaN NaN
2 456.0 def
3 NaN NaN
It looks like the skip_blank_lines=True
argument is ignored, as the dataframe contains NaN's.
What should be the valid combination of pandas.read_fwf()
arguments that would ensure the skipping of blank lines?