[PYTHON] Ignore # line and read in pandas

TL;DR

In the case of csv files, I don't think that there is a comment-out line in the line that starts with #, but bioinformatics-specific gff, vcf, bed, etc. contain comment lines and are normally read by pandas. It was annoying, so I looked it up. Since pandas is smart, it seems to have such a function.

comment argument

The solution is very simple, just put the first symbol in the comment in the comment argument when loading.

import pandas as pd


df = pd.read_csv("/path/to/file", comment='#')

This eliminates the frustration that cannot be read ...

Recommended Posts

Ignore # line and read in pandas
Preserve and read order in PyYAML
Create and read messagepacks in Python
Line graphs and scale lines in python
Read the file line by line in Python
Read the file line by line in Python
Read and write JSON files in Python
How to read CSV files in Pandas
[Python] Read the specified line in the file
Read CSV and analyze with Pandas and Seaborn
Read pandas data
Header shifts in read_csv () and read_table () of Pandas
Add totals to rows and columns in pandas
Read DXF in python
Learn Pandas in 10 minutes
jupyter and pandas installation
[Python] Read Japanese csv with pandas without garbled characters (and extract columns written in Japanese)
UnicodeDecodeError in pandas read_csv
pandas index and reindex
Read the csv file and display it in the browser
Read CSV file: pandas
Read and write single precision floating point in Python
pandas resample and rolling
Read XBRL and easily visualize changes in business performance
[In one line] Visualize like a lawn with just Pandas
Tips for coding short and easy to read in Python
Read json in C # and convert to dictionary type (forced)
Graph time series data in Python using pandas and matplotlib
How to create dataframes and mess with elements in pandas
Read and write csv file
Read csv with python pandas
Correspondence between pandas and SQL
Fizzbuzz in Python (in one line)
Clipping and normalization in TensorFlow
Read Euler's formula in Python
Key additions to pandas 1.1.0 and 1.0.0
Read and write a file
Try LINE Notify in Python
Read Namespace-specified XML in Python
Read Outlook emails in Python
Read / write between BigQuery ↔ Pandas
Stack and Queue in Python
Write and read a file
Unittest and CI in Python
Swap columns in pandas dataframes
Read Fortran output in python
Read big endian binary in Python and convert it to ndarray
Read an Excel sheet and loop it line by line Python VBA
[Python3] Save the mean and covariance matrix in json with pandas
I want to make the second line the column name in pandas
Browse .loc and .iloc at the same time in pandas DataFrame