Python Forum
[split] how to read a specific row in CSV file ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] how to read a specific row in CSV file ?
#1
how to read a specific row in CSV file ?
Reply
#2
Want to read the specific row number or what is the criteria?.

Use pandas to readcsv, output will be dataframe.
Using dataframe we can add multiple criteria to fetch required rows.

import pandas as pd

ot = pd.read_csv(r'Values.csv')
print("Full data",ot)

#Select specific columns of your dataframe
print(ot['name'])

#select values based on criteria
print(ot[ot.name == 'an'])
Let me know if your requirement is different.

Output:
Output: Full data name mob 0 aj 99 1 an 73 specific column name 0 aj 1 an Fetch only an name mob 1 an 73
Reply
#3
CSV is not random access, so you must read sequentially in a loop
if that loop is enumerated, you can generate the row number (index actually)
https://docs.python.org/3/library/functi...#enumerate
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using regex to count specific character in file shamishd 1 1,624 Oct-01-2021, 07:33 AM
Last Post: snippsat
  Can we store value in file if we open file in read mode? prasanthbab1234 3 2,575 Sep-26-2020, 12:10 PM
Last Post: ibreeden
  Read data from a CSV file in S3 bucket and store it in a dictionary in python Rupini 3 6,999 May-15-2020, 04:57 PM
Last Post: snippsat
  Read text file, process data and print specific output Happythankyoumoreplease 3 2,922 Feb-20-2020, 12:19 PM
Last Post: jefsummers
  read from file mcgrim 16 6,165 May-14-2019, 10:31 AM
Last Post: mcgrim
  To extract a specific column from csv file and compute the average vicson 2 8,111 Oct-20-2018, 03:18 AM
Last Post: vicson
  Read directly from excel file using python script dvldgs05 0 2,257 Oct-19-2018, 02:51 AM
Last Post: dvldgs05
  write split words of sentence to file bluefrog 1 2,989 Aug-27-2018, 01:28 AM
Last Post: micseydel
  Read a data from text file (Notepad) Leonzxd 24 13,914 May-23-2018, 12:17 AM
Last Post: wavic
  Homework - Read from/Write to file (renamed from Help help help) Amitkafle 1 3,050 Jan-11-2018, 07:24 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020