2017-03-09 378 views
-1

我想導入.dat文件,其中包括導入.dat文件在Python 3

lines/header/numbers/lines 

這樣的例子

start using data to calculate something 
x y z g h 
1 4 6 8 3 
4 5 6 8 9 
2 3 6 8 5 
end the data that I should import. 

現在我試圖讀取該文件,刪除第一和最後一行,並把數字放在一個數組中,並對它們做一些基本計算,但是我無法擺脫這些線條。我用data = np.genfromtxt('sample.dat')來導入數據,但用線條,我什麼也做不了。誰能幫我?

回答

0

也許這可以幫助你:

import numpy as np 

data = np.genfromtxt('sample.dat', 
        skip_header=1, 
        skip_footer=1, 
        names=True, 
        dtype=None, 
        delimiter=' ') 
print(data) 
# Output: [(1, 4, 6, 8, 3) (4, 5, 6, 8, 9) (2, 3, 6, 8, 5)]