I have table formatted as follow :
foo - bar - 10 2e-5 0.0 some information quz - baz - 4 1e-2 1 some other description in here
When I open it with pandas doing :
a = pd.read_table("file", header=None, sep=" ")
It tells me :
CParserError: Error tokenizing data. C error: Expected 9 fields in line 2, saw 12
What I'd basically like to have is something similar to the skiprows option which would allow me to do something like :
a = pd.read_table("file", header=None, sep=" ", skipcolumns=[8:])
I'm aware that I could re-format this table with awk
, but I'd like to known whether a Pandas solution exists or not.
Thanks.
We can exclude one column from the pandas dataframe by using the loc function. This function removes the column based on the location. Parameters: dataframe: is the input dataframe.
Skip Columns From Excel Sheet Sometimes while reading an excel sheet into pandas DataFrame you may need to skip columns, you can do this by using usecols param. This takes values {int, str, list-like, or callable default None}. To specify the list of column names or positions use a list of strings or a list of int.
The usecols
parameter allows you to select which columns to use:
a = pd.read_table("file", header=None, sep=" ", usecols=range(8))
However, to accept irregular column counts you need to also use engine='python'
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With