本文介绍了如何将tsv文件加载到Pandas DataFrame中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是python和pandas的新手.我正在尝试将tsv
文件加载到熊猫DataFrame
中.
I'm new to python and pandas. I'm trying to get a tsv
file loaded into a pandas DataFrame
.
这是我正在尝试的错误,也是我得到的错误:
This is what I'm trying and the error I'm getting:
>>> df1 = DataFrame(csv.reader(open('c:/~/trainSetRel3.txt'), delimiter='\t'))
Traceback (most recent call last):
File "<pyshell#28>", line 1, in <module>
df1 = DataFrame(csv.reader(open('c:/~/trainSetRel3.txt'), delimiter='\t'))
File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 318, in __init__
raise PandasError('DataFrame constructor not properly called!')
PandasError: DataFrame constructor not properly called!
推荐答案
注意:从17.0开始,不鼓励使用from_csv
:请改用pd.read_csv
Note: As of 17.0 from_csv
is discouraged: use pd.read_csv
instead
文档列出了 .from_csv 似乎可以完成您想要的功能:
The documentation lists a .from_csv function that appears to do what you want:
DataFrame.from_csv('c:/~/trainSetRel3.txt', sep='\t')
如果有标题,则可以传递header=0
.
If you have a header, you can pass header=0
.
DataFrame.from_csv('c:/~/trainSetRel3.txt', sep='\t', header=0)
这篇关于如何将tsv文件加载到Pandas DataFrame中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!