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