Python 入門練習--讀取數據,並將某幾列的數據賦值給變量


There are many commands that can load data into Python. Here I use genfromtxt and loadtxt as example.

1 import numpy as np
2 my_data = np.genfromtxt('name_of_the_data', skip_header=10) # skip the first 10 rows of the data, and the true data is loaded from line 11

or

1 import numpy as np
2 my_data = np.loadtxt('before.dump',skiprows=10) # skip the first 10 rows of the data, and the true data is loaded from line 11
1 x = my_data[:,3]  # extract x from data, assign data we need to x 
2 y = my_data[:,4]  # the colon represents all values. [:,4] means all the values of column 5
3 z = my_data[:,8]  #                                  [3,:] means all the values of row 4

~~~~~~

1 # Get help of these two commands
2 help(np.loadtxt)
3 help(np.genfromtxt)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM