pandas :将TSV读入DataFrame [英] Pandas: Reading TSV into DataFrame

查看:150
本文介绍了 pandas :将TSV读入DataFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python 2.7,并具有如下格式的TSV(368行×3列):

I'm using Python 2.7 and have a TSV formatted as follows (368 rows × 3 columns):

date    dayOfWeek    pageviews
2016    4            3920
...

我有一个Jupyter笔记本电脑,保存在与TSV相同的位置.我正在运行以下代码:

I have a Jupyter notebook saved in the same location as the TSV. I'm running this code:

import pandas as pd
pd.read_table('query_explorer.tsv')

我得到一个736行×3列的数据帧,并用NaN填充.这也很有趣,因为我应该只有368行(恰好是我的一半).

I get back a dataframe that's 736 rows × 3 columns and filled with NaNs. It's interesting too, because I should have only 368 rows (exactly half of what I do have).

知道这是怎么回事吗?

推荐答案

怎么样:

pd.read_table('query_explorer.tsv',delim_whitespace=True,header=0)

这篇关于 pandas :将TSV读入DataFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆