I have a .text
file with following format, where fields (index number, name and message) are separated by \t
(tab-separated):
712 ben Battle of the Books
713 james i used to be in TOM
714 tomy i was in BOB once
715 ben Tournaments of Minds
716 tommy Also the Lion in the upcoming school play
717 tommy Can you guess
718 tommy P
...
which I read with read_csv
into a data frame:
chat = pd.read_csv("f.text", sep = "\t", header = None, usecols = [2])
But the data frame just has 9812
rows while the ordinary file has more than 12428
rows (just 21 empty lines). It is quite weird. Do you have any idea? Thanks.
lineterminator
ofread_csv
. Or you can try addindex_col=None
.How you check length ofdf
? Byprint len(df)
? – Acrosstheboardprint df
It will show the row number under the table. Same result withlen(df)
– Hortensiahorterusecols
,length
is still wrong? – Acrosstheboard12428
lines. – Hortensiahorterchat = pd.read_csv("f.text", skiprows=9810, sep = "\t", header = None, usecols = [2])
, then maybe check columnsprint df.columns
and indexprint df.index
– Acrosstheboard