python - pandas read_csv end of section flag -
is there smart/easy way tell read_csv in pandas not load data after "end of section" flag? or stop if gets empty row?
data = pd.read_csv(path, **params) eos_line = (data['id'] == eos_string).idxmax() data = data.drop(range(eos_line-2, data.shape[0]))
i feel ought better way. unfortunately don't know number of rows or length of footer want skip before calling read_csv. data looks like
1,2,3 4,5,6 dont want data after line 7,8,9 10,11,12
(note: -2 b/c there 2 empty rows before end of section string, if read_csv read until point guess dropna() remove these 2 rows pretty painlesslly)
wes did think of everything!
in [40]: data = """a,b,c ....: 1,2,3 ....: 4,5,6 ....: 7,8,9 ....: want skip ....: also skip ....: """ in [41]: read_csv(stringio(data), skip_footer=2) out[41]: b c 0 1 2 3 1 4 5 6 2 7 8 9
Comments
Post a Comment