0

I have a csv file with list of client details. I am pulling out a particular column from that file with this code:

import csv

details = []
with open("userlist.csv", "r", encoding="utf8") as csv_file:
    csv_reader = csv.reader(csv_file, delimiter=',')
    for lines in csv_reader:
      description.append(lines[27])
print (details)

I am getting this output in a list for multiple rows:'

[Description]

sentence1

[Issue Details]

*** Bunch of other data """

timestamp":12:42PM

,

emailaddress:xyz@gmail.com

', '

[Description]

aaa

[Issue Details]

*** Bunch of other data """

timestamp":10:12AM,

emailaddress:mmm@gmail.com

'

Now I want to extract the emailID of the user. So how should I do that?

Red
  • 26,798
  • 7
  • 36
  • 58

1 Answers1

0

I suggest you to use the pandas module and from it load a CSV file to a DataFrame() function. Within it, you can easily extra the emailID.

import pandas as pd
df = pd.read_csv('userlist.csv')

Then from the df variable, you can easily do df['emailID']

Aleksander Ikleiw
  • 2,549
  • 1
  • 8
  • 26
  • Getting this error if I use df['emailID']: Traceback (most recent call last): File "C:\***\pandas\core\indexes\base.py", line 2646, in get_loc return self._engine.get_loc(key) File "pandas\_libs\index.pyx", line 111 & line 138, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\hashtable_class_helper.pxi", line 1619 & line 1627, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'emailID' – Python4test2 Jul 15 '20 at 00:14
  • @Python4test2 I do not know your `CSV` file structure. between `[]` you have to put the name of a column. – Aleksander Ikleiw Jul 15 '20 at 07:22
  • My CSV file has a column name details. For that column, each row contains lots of information along with email address. For ex. each row for in "details" column has username, age, height, weight, emailID etc. In this case, how do I get the email address? – Python4test2 Jul 15 '20 at 18:37