用pandas从txt加载数据 [英] Load data from txt with pandas
问题描述
我正在加载一个包含浮点数据和字符串数据的 txt 文件.我想将它们存储在一个数组中,我可以在其中访问每个元素.现在我只是在做
I am loading a txt file containig a mix of float and string data. I want to store them in an array where I can access each element. Now I am just doing
import pandas as pd
data = pd.read_csv('output_list.txt', header = None)
print data
这是输入文件的结构:1 0 2000.0 70.2836942112 1347.28369421/file_address.txt
.
This is the structure of the input file: 1 0 2000.0 70.2836942112 1347.28369421 /file_address.txt
.
现在数据作为唯一列导入.我该如何划分它,以便分别存储不同的元素(以便我可以调用 data[i,j]
)?以及如何定义标题?
Now the data are imported as a unique column. How can I divide it, so to store different elements separately (so I can call data[i,j]
)? And how can I define a header?
推荐答案
您可以这样做:
import pandas as pd
df = pd.read_csv('file_locationfilename.txt', delimiter = " ")
(like, df = pd.read_csv('F:Desktopds ext.txt', delimiter = " ")
(like, df = pd.read_csv('F:Desktopds ext.txt', delimiter = " ")
这篇关于用pandas从txt加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!