简体   繁体   English

从文本文件Pandas中读取列

[英]Reading in Columns from a text file Pandas

I have a large .txt file (many GB) in the the format: 我有一个很大的.txt文件(很多GB),格式为:

|Column1|Column2|Column3|Column4
|"text"|"text"|"text"|"text"
|"text"|"text"|"text"|"text"

I would like to read this data straight into a pandas dataframe. 我想将此数据直接读入pandas数据框。 Is this possible with a pandas command eg 这是可能的熊猫命令,例如

df = pd.read_XXX()

If not with pandas, can someone advise on how to read in a file of this type? 如果不使用熊猫,有人可以建议如何读取此类文件吗? I am not familiar with this format. 我不熟悉这种格式。

Use .pd.read_csv like this 像这样使用.pd.read_csv

df = pd.read_csv('untitled.txt', sep = '|')

在此处输入图片说明

You are dealing with a csv file (comma seperated value). 您正在处理的是csv文件(逗号分隔值)。

You read this file in pandas with: 您可以通过以下方式在pandas中读取此文件:

df = pd.read_csv('filename.txt', sep='|')

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

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