在大 pandas 中阅读没有标题的制表符分隔数据 [英] reading tab-delimited data without header in pandas

查看:129
本文介绍了在大 pandas 中阅读没有标题的制表符分隔数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用 pandas 打开不带标题的制表符分隔数据。

I'm having trouble using pandas to open tab-delimited data without headers.

我的测试数据(实际上包含200行,其中显示了前10个):

My test data (actually contains 200 lines, of which I am showing the first 10):

Tag19184    CTAAC   hffef   1   a   36  -   chr1    10006   0   36M 36
Tag19184    CTAAC   hffef   1   a   36  -   chr1    10012   0   36M 36
Tag19184    CTAAC   hffef   1   a   36  -   chr1    10018   0   36M 36
Tag19184    CTAAC   hffef   1   a   36  -   chr1    10024   0   36M 36
Tag19184    CTAAC   hffef   1   a   36  -   chr1    10030   0   36M 36
Tag19184    CTAAC   hffef   1   a   36  -   chr1    10036   0   36M 36
Tag19184    CTAAC   hffef   1   a   36  -   chr1    10042   0   36M 36
Tag20198    CTAAC   hffef   1   a   36  -   chr1    10048   0   36M 36
Tag20198    CTAAC   hffef   1   a   36  -   chr1    10054   0   36M 36
Tag45093    CTAAC   hffef   1   a   36  -   chr1    10060   0   36M 36

我的代码:

import pandas as pd
df = pd.read_csv('in_test.txt',sep='\t',header=None)
print df

但是,我得到以下输出,我不认为我可以用来进一步处理数据(?):

However, I get the following output, which I don't think I can use to further process data (?):

<class 'pandas.core.frame.DataFrame'>
Int64Index: 200 entries, 0 to 199
Data columns:
X.1     200  non-null values
X.2     200  non-null values
X.3     200  non-null values
X.4     200  non-null values
X.5     200  non-null values
X.6     200  non-null values
X.7     200  non-null values
X.8     200  non-null values
X.9     200  non-null values
X.10    200  non-null values
X.11    200  non-null values
X.12    200  non-null values
dtypes: int64(5), object(7)

此处的教程表明 print df 应该给我相应的数据框。我做错了什么?

The tutorial here suggests that print df should just give me the corresponding data frame. What am I doing wrong?

推荐答案

我想你正在读取它,但是:

I think you are getting the it read correctly, but:


  1. 请参阅:更改大熊猫0.13.0打印数据帧打印像早期版本的数据框,这是老版本中的大熊猫做的。所以,更新将解决它。

  2. 您可以使用 ipython笔记本,其中 DataFrames 将显示为HTML表格。

  3. 您可以使用 df.head(5)(类似于 DataFrame 的 c>是正确的。

  1. See: change pandas 0.13.0 "print dataframe" to print dataframe like in earlier versions, this is what pandas do in the older versions. So, update will solve it.
  2. You can use ipython notebook, where DataFrames will show up as HTML tables.
  3. You can use df.head(5) (similar to r's head) to get the first a few rows just to make sure your DataFrame is correct.

这篇关于在大 pandas 中阅读没有标题的制表符分隔数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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