Getting specific line and value with Python DictReader

后端 未结 4 853
终归单人心
终归单人心 2021-01-14 08:28

I have a csv file and am trying to get one specific value on, say, line 20, column 3.

But so far, all I managed is to display all values on column 3 (here c

4条回答
  •  温柔的废话
    2021-01-14 08:50

    Naive solution:

      target_row = 5
      for num, line in enumerate(d):
          if num == target_row:
              print line["name"]
              break
    

    I removed the intermediate variable score.

    Note that this is non-optimal, as you iterate until you reach the desired row, but I don't know if there is random access to lines in the DictReader.

提交回复
热议问题