[英]Pandas: Reading TSV into DataFrame
I'm using Python 2.7 and have a TSV formatted as follows (368 rows × 3 columns):我正在使用 Python 2.7,并且 TSV 的格式如下(368 行 × 3 列):
date dayOfWeek pageviews
2016 4 3920
...
I have a Jupyter notebook saved in the same location as the TSV.我有一个 Jupyter 笔记本保存在与 TSV 相同的位置。 I'm running this code:
我正在运行这段代码:
import pandas as pd
pd.read_table('query_explorer.tsv')
I get back a dataframe that's 736 rows × 3 columns and filled with NaNs.我得到了一个 736 行 × 3 列并填充了 NaN 的数据框。 It's interesting too, because I should have only 368 rows (exactly half of what I do have).
这也很有趣,因为我应该只有 368 行(正好是我的一半)。
Any idea what's going on here?知道这里发生了什么吗?
怎么样:
pd.read_table('query_explorer.tsv',delim_whitespace=True,header=0)
In csv
files comma is the separator.在
csv
文件中,逗号是分隔符。 For tsv
files, the tab character will separate each field.对于
tsv
文件,制表符将分隔每个字段。 pandas
according to separator can recognize and separate columns. pandas
根据分隔符可以识别和分隔列。
import pandas as pd
pd.read_csv('query_explorer.tsv',sep="\t")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.