简体   繁体   English

如何使用Pandas从.txt文件读取原始文本?

[英]How to read raw text from .txt file using Pandas?

My text file has values like this: 我的文本文件具有以下值:

00001
00002
00003

The pandas.read_csv function reads the values as 1, 2, 3 . pandas.read_csv函数读取值为1, 2, 3 I want them to be read in raw format as 00001 etc. 我希望以原始格式读取它们,如00001等。

How can I do this? 我怎样才能做到这一点?

converters

The key 0 in the dictionary {0: str} refers to either the column name or position. 字典{0: str}的键0表示列名或位置。 In this case, it is both. 在这种情况下,两者都是。

pd.read_csv('tst.csv', header=None, converters={0: str})

       0
0  00001
1  00002
2  00003

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM