第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

使用python從文本文件中的列中提取數(shù)據(jù)

使用python從文本文件中的列中提取數(shù)據(jù)

胡子哥哥 2023-06-27 14:34:46
我是 python 文件數(shù)據(jù)處理的新手。我有以下文本文件,其中包含新大學(xué)校園的報(bào)告。我想從“colleges”列和“book_IDs_1”中提取 block_ABC_top 的數(shù)據(jù),即 23。我還想知道在 Colleges 列中是否再出現(xiàn) block_ABC_top 并找到 book IDs_1 列的值??梢栽谖谋疚募袉??或者我必須將其更改為csv?我如何編寫(xiě)此數(shù)據(jù)處理的代碼?請(qǐng)幫助我!Copyright 1986-2019, Inc. All Rights Reserved.Design Information-----------------------------------------------------------------------------------------------------------------| Version : (lin64) Build 2729669 Thu Dec  5 04:48:12 MST 2019| Date         : Wed Aug 26 00:46:08 2020| Host         : running 64-bit Red Hat Enterprise Linux Server release 7.8 | Command      : college report| Design       : college| Device       : laptop| Design State : in construction-----------------------------------------------------------------------------------------------------------------Table of Contents-----------------1. Information by Hierarchy1. Information by Hierarchy---------------------------+----------------------------------------------+--------------------------------------------+------------+------------+---------+------+-----+|                   colleges                   |                   Module                   | Total mems | book IDs_1 | canteen | BUS  | UPS | +----------------------------------------------+--------------------------------------------+------------+------------+---------+------+-----+| block_ABC_top                                |                                      (top) |         44 |         23 |       8 |    8 |   8 |   |    (block_ABC_top_0)                         |                            block_ABC_top_0 |          5 |          5 |       5 |    2 |   9 |       +----------------------------------------------+--------------------------------------------+------------+------------+---------+------+-----+我有一個(gè)數(shù)據(jù)列表,其中包含大學(xué)的數(shù)據(jù),例如 block_ABC_top、block_ABC_top_1、block_ABC_top、block_ABC_top_1...這是我下面的代碼我面臨的問(wèn)題是..它只獲取 data[0] 的數(shù)據(jù)..但我有data[0] 和 data[2] 具有同一所大學(xué),我希望檢查發(fā)生兩次
查看完整描述

3 回答

?
肥皂起泡泡

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超6個(gè)贊

print [x.split(' ')[0] for x in open(file).readlines()]  #colleges column
print [x.split(' ')[3] for x in open(file).readlines()]  #book_IDs_1 column

嘗試運(yùn)行這些。


查看完整回答
反對(duì) 回復(fù) 2023-06-27
?
陪伴而非守候

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超8個(gè)贊

更好的方法是使用該split()函數(shù),而不是使用到達(dá)字段的確切位置,因?yàn)槟淖侄斡蓔符號(hào)分隔。您可以循環(huán)遍歷文件的行并相應(yīng)地處理它們。


for loop...:

    line_values = line.split("|")


print(line_values[0]) # block_ABC_top


查看完整回答
反對(duì) 回復(fù) 2023-06-27
?
楊魅力

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超6個(gè)贊

要提取 Book id 列數(shù)據(jù),請(qǐng)使用下面的代碼


with open('report.txt') as f:

  for line in f:

    if 'block_ABC_top' in line:

      line_values = line.split('|')

      print(line_values[4]) # PRINTS 23 AND 5


查看完整回答
反對(duì) 回復(fù) 2023-06-27
  • 3 回答
  • 0 關(guān)注
  • 194 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)