-2

In my CSV file there is 10 lines of data and each line consist of 1 person's account details.

heres 2 lines of my file for example:

Name:Email:Password

Matt,Matt@gmail.com,123456
John,John@gmail.com,123456

So now in my python script lets say i wanna get line number 2's email (John@gmail.com), how to do that?

jasonmur
  • 19
  • 4
  • 1
    This is not a question. This is a work order. "I have this in input, I need this output" is something you tell an employee. Ask a question about code you wrote. There are *so many* Python questions about handling CSV on this site alone that the hardest part for you will be to pick one to learn from. Read a couple dozen and when you have own ocde to ask a question about, come back and ask it. – Tomalak Apr 05 '21 at 07:07

2 Answers2

1

THis should work, of course you need to have pandas installed.

import pandas as pd
df = pd.read_csv('your.csv',header=False)
print(df[1][1])
Marco
  • 1,952
  • 1
  • 17
  • 23
0

You can use pandas to load only certain rows from a CSV.

Code:

import pandas as pd

# Select second row
row_to_select = 2
input_file = '/content/sample_2.csv'

# You can use skiprows to skip unwanted rows
data = pd.read_csv(infile, skiprows=lambda x: x not in range(row_to_select, row_to_select+1))

# Convert the column dataframe to list if necessary
print(list(data))

Output:

['John', 'John@gmail.com', '123456']
GTS
  • 56
  • 6