-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,[email protected],123456
John,[email protected],123456

So now in my python script lets say i wanna get line number 2's email ([email protected]), how to do that?

1
  • 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. Commented Apr 5, 2021 at 7:07

2 Answers 2

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])
Sign up to request clarification or add additional context in comments.

Comments

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', '[email protected]', '123456']

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.