简体   繁体   中英

reading the tex file in Python with many column

For reading the data file I have always used the following code

zx, Dx, sigx = np.genfromtxt('data/TEST.txt',unpack=True)

this txt file has 3 column and 1000 rows.

Now I have a text file with 3000 columns and 1000 rows like

zx, Dx, sigx, sigu, sigi, siga,..., 1000th_column

how should I read it while having option to call the values of any column I want?

because in previous code I called zx[n] but here the number of columns are to hight to define in the code.

thank you for your help

I will advice you to use pandas like this:

import pandas as pd

df = pd.read_csv('data/TEST.txt', sep=",") # Change the seprarator to match your data

Then you can call call and row like this.

df["zx"][n]

Edit

If you want to read column 890 and row 500 you do like this.

df.iloc[500, 890]

Here is documention about iloc .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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