Python (3.4.3) ile pandalarda (0.18.1) read_fwf
işlevini kullanarak sabit genişlikli dosyaları okurken, bunu yapmak mümkündür. comment
bağımsız değişkenini kullanarak bir yorum karakteri belirtin. Yorum karakteri ile başlayan tüm satırların göz ardı edilmesini bekledim. Ancak, dosyada ilk sütunu colspecs
'daki herhangi bir sütunda belirtmezseniz, yorum karakteri kullanılmaz.read_fwf, colspecs argümanı ilk sütunu içermiyorsa yorum karakterini kullanmaz
import io, sys
import pandas as pd
sys.version
# '3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)]'
pd.__version__
# '0.18.1'
# Two input files, first line is comment, second line is data.
# Second file has a column (with the letter A)
# that I don't want at start of data.
string = "#\n1K\n"
off_string = "#\nA1K\n"
# When using skiprows to skip commented row, both work.
pd.read_fwf(io.StringIO(string), colspecs = [(0,1), (1,2)], skiprows = 1, header = None)
# 0 1
# 0 1 K
pd.read_fwf(io.StringIO(off_string), colspecs = [(1,2), (2,3)], skiprows = 1, header = None)
# 0 1
# 0 1 K
# If a comment character is specified, it only works when the colspecs
# includes the column with the comment character.
pd.read_fwf(io.StringIO(string), colspecs = [(0,1), (1,2)], comment = '#', header = None)
# 0 1
# 0 1 K
pd.read_fwf(io.StringIO(off_string), colspecs = [(1,2), (2,3)], comment = '#', header = None)
# 0 1
# 0 NaN NaN
# 1 1.0 K
Özel olarak bununla ilgili herhangi bir belge var mı? Basit bir çözüm, ilk sütunu dahil etmek ve daha sonra kaldırmaktır, ancak bunun bir hata mı, yoksa yanlış anlaşılma ihtimalini mi tahmin ettiğimi doğrulamak istedim.
Yorum bayrağı için gerekli belgeler: http://pandas.pydata.org/pandas-docs/stable/io.html#comments-and-empty-lines – ode2k