作者phoebejen (phoebe)
看板Python
標題[問題] 關於txt資料讀列的問題
時間Tue Mar 20 13:34:12 2018
如圖
https://imgur.com/a/4I4ZQ
我想要讀的是第二列的資料
但資料讀成都會變成
4
1
9
7
這是第二列數字的意思
請問是否是不能打Line的語法呢?
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.25.192.242
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Python/M.1521524054.A.56B.html
1F:推 Panthalassa: 要先 split, 看起來是用 \t 分隔的? 03/20 13:44
2F:→ Panthalassa: 可以 print(line.split(‘\t’)[1])。如果要去掉 03/20 13:44
3F:→ Panthalassa: 換行符號,後面加 [0:-1] 或 .replace(‘\n’,’’) 03/20 13:44
謝謝P大,用1是指第一行對吧,Split是空白分割的意思
4F:推 vfgce: python的list是從0開始... 03/20 13:57
5F:→ TuCH: f.readlines()[1] 03/20 13:58
6F:推 vfgce: 他要的是第二column,不是第二row. 03/20 14:00
對,不好意思沒講清楚,我是要4.32的那一欄~
※ 編輯: phoebejen (114.25.192.242), 03/20/2018 14:02:46
※ 編輯: phoebejen (114.25.192.242), 03/20/2018 14:18:02
7F:→ Panthalassa: 從圖片中看 感覺分隔的不是空白 而是TAB (\t) 03/20 14:26