Python - CSV Module - How to Read, Parse, and Write CSV Files
** CSV Module - How to Read, Parse, and Write CSV Files
==========================================
import csv
with open('names2.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file)
for line in csv_reader:
print(line)
---------------------------------
['first_name', 'last_name', 'email']
['John', 'Doe', 'john-doe@linuxerhan.com']
['Mary', 'Smith-Robinson', 'maryjacobs@linuxerhan.com']
['Dave', 'Smith', 'davesmith@linuxerhan.com']
['Jane', 'Stuart', 'janestuart@linuxerhan.com']
['Tom', 'Wright', 'tomwright@linuxerhan.com']
['Steve', 'Robinson', 'steverobinson@linuxerhan.com']
['Nicole', 'Jacobs', 'nicolejacobs@linuxerhan.com']
['Jane', 'Wright', 'janewright@linuxerhan.com']
['Jane', 'Doe', 'janedoe@linuxerhan.com']
['Kurt', 'Wright', 'kurtwright@linuxerhan.com']
['Kurt', 'Robinson', 'kurtrobinson@linuxerhan.com']
['Jane', 'Jenkins', 'janejenkins@linuxerhan.com']
['Neil', 'Robinson', 'neilrobinson@linuxerhan.com']
['Tom', 'Patterson', 'tompatterson@linuxerhan.com']
['Sam', 'Jenkins', 'samjenkins@linuxerhan.com']
['Steve', 'Stuart', 'stevestuart@linuxerhan.com']
['Maggie', 'Patterson', 'maggiepatterson@linuxerhan.com']
['Maggie', 'Stuart', 'maggiestuart@linuxerhan.com']
['Jane', 'Doe', 'janedoe@linuxerhan.com']
['Steve', 'Patterson', 'stevepatterson@linuxerhan.com']
['Dave', 'Smith', 'davesmith@linuxerhan.com']
['Sam', 'Wilks', 'samwilks@linuxerhan.com']
['Kurt', 'Jefferson', 'kurtjefferson@linuxerhan.com']
['Sam', 'Stuart', 'samstuart@linuxerhan.com']
['Jane', 'Stuart', 'janestuart@linuxerhan.com']
['Dave', 'Davis', 'davedavis@linuxerhan.com']
['Sam', 'Patterson', 'sampatterson@linuxerhan.com']
['Tom', 'Jefferson', 'tomjefferson@linuxerhan.com']
['Jane', 'Stuart', 'janestuart@linuxerhan.com']
['Maggie', 'Jefferson', 'maggiejefferson@linuxerhan.com']
['Mary', 'Wilks', 'marywilks@linuxerhan.com']
['Neil', 'Patterson', 'neilpatterson@linuxerhan.com']
['Corey', 'Davis', 'coreydavis@linuxerhan.com']
['Steve', 'Jacobs', 'stevejacobs@linuxerhan.com']
['Jane', 'Jenkins', 'janejenkins@linuxerhan.com']
['John', 'Jacobs', 'johnjacobs@linuxerhan.com']
['Neil', 'Smith', 'neilsmith@linuxerhan.com']
['Corey', 'Wilks', 'coreywilks@linuxerhan.com']
['Corey', 'Smith', 'coreysmith@linuxerhan.com']
['Mary', 'Patterson', 'marypatterson@linuxerhan.com']
['Jane', 'Stuart', 'janestuart@linuxerhan.com']
['Travis', 'Arnold', 'travisarnold@linuxerhan.com']
['John', 'Robinson', 'johnrobinson@linuxerhan.com']
['Travis', 'Arnold', 'travisarnold@linuxerhan.com']
---------------------------------
==========================================
import csv
with open('names2.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file)
for line in csv_reader:
print(line[2])
---------------------------------
email
john-doe@linuxerhan.com
maryjacobs@linuxerhan.com
davesmith@linuxerhan.com
janestuart@linuxerhan.com
tomwright@linuxerhan.com
steverobinson@linuxerhan.com
nicolejacobs@linuxerhan.com
janewright@linuxerhan.com
janedoe@linuxerhan.com
kurtwright@linuxerhan.com
kurtrobinson@linuxerhan.com
janejenkins@linuxerhan.com
neilrobinson@linuxerhan.com
tompatterson@linuxerhan.com
samjenkins@linuxerhan.com
stevestuart@linuxerhan.com
maggiepatterson@linuxerhan.com
maggiestuart@linuxerhan.com
janedoe@linuxerhan.com
stevepatterson@linuxerhan.com
davesmith@linuxerhan.com
samwilks@linuxerhan.com
kurtjefferson@linuxerhan.com
samstuart@linuxerhan.com
janestuart@linuxerhan.com
davedavis@linuxerhan.com
sampatterson@linuxerhan.com
tomjefferson@linuxerhan.com
janestuart@linuxerhan.com
maggiejefferson@linuxerhan.com
marywilks@linuxerhan.com
neilpatterson@linuxerhan.com
coreydavis@linuxerhan.com
stevejacobs@linuxerhan.com
janejenkins@linuxerhan.com
johnjacobs@linuxerhan.com
neilsmith@linuxerhan.com
coreywilks@linuxerhan.com
coreysmith@linuxerhan.com
marypatterson@linuxerhan.com
janestuart@linuxerhan.com
travisarnold@linuxerhan.com
johnrobinson@linuxerhan.com
travisarnold@linuxerhan.com
---------------------------------
==========================================
import csv
with open('names2.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file)
next(csv_reader)
for line in csv_reader:
print(line[2])
---------------------------------
john-doe@linuxerhan.com
maryjacobs@linuxerhan.com
davesmith@linuxerhan.com
janestuart@linuxerhan.com
tomwright@linuxerhan.com
steverobinson@linuxerhan.com
nicolejacobs@linuxerhan.com
janewright@linuxerhan.com
janedoe@linuxerhan.com
kurtwright@linuxerhan.com
kurtrobinson@linuxerhan.com
janejenkins@linuxerhan.com
neilrobinson@linuxerhan.com
tompatterson@linuxerhan.com
samjenkins@linuxerhan.com
stevestuart@linuxerhan.com
maggiepatterson@linuxerhan.com
maggiestuart@linuxerhan.com
janedoe@linuxerhan.com
stevepatterson@linuxerhan.com
davesmith@linuxerhan.com
samwilks@linuxerhan.com
kurtjefferson@linuxerhan.com
samstuart@linuxerhan.com
janestuart@linuxerhan.com
davedavis@linuxerhan.com
sampatterson@linuxerhan.com
tomjefferson@linuxerhan.com
janestuart@linuxerhan.com
maggiejefferson@linuxerhan.com
marywilks@linuxerhan.com
neilpatterson@linuxerhan.com
coreydavis@linuxerhan.com
stevejacobs@linuxerhan.com
janejenkins@linuxerhan.com
johnjacobs@linuxerhan.com
neilsmith@linuxerhan.com
coreywilks@linuxerhan.com
coreysmith@linuxerhan.com
marypatterson@linuxerhan.com
janestuart@linuxerhan.com
travisarnold@linuxerhan.com
johnrobinson@linuxerhan.com
travisarnold@linuxerhan.com
---------------------------------
==========================================
import csv
with open('names2.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file)
with open('new_names2.csv', 'w') as new_file:
csv_writer = csv.writer(new_file, delimiter = '-')
for line in csv_reader:
csv_writer.writerow(line)
---------------------------------
first_name-last_name-email
John-Doe-"john-doe@linuxerhan.com"
Mary-"Smith-Robinson"-maryjacobs@linuxerhan.com
Dave-Smith-davesmith@linuxerhan.com
Jane-Stuart-janestuart@linuxerhan.com
Tom-Wright-tomwright@linuxerhan.com
Steve-Robinson-steverobinson@linuxerhan.com
Nicole-Jacobs-nicolejacobs@linuxerhan.com
Jane-Wright-janewright@linuxerhan.com
Jane-Doe-janedoe@linuxerhan.com
Kurt-Wright-kurtwright@linuxerhan.com
Kurt-Robinson-kurtrobinson@linuxerhan.com
Jane-Jenkins-janejenkins@linuxerhan.com
Neil-Robinson-neilrobinson@linuxerhan.com
Tom-Patterson-tompatterson@linuxerhan.com
Sam-Jenkins-samjenkins@linuxerhan.com
Steve-Stuart-stevestuart@linuxerhan.com
Maggie-Patterson-maggiepatterson@linuxerhan.com
Maggie-Stuart-maggiestuart@linuxerhan.com
Jane-Doe-janedoe@linuxerhan.com
Steve-Patterson-stevepatterson@linuxerhan.com
Dave-Smith-davesmith@linuxerhan.com
Sam-Wilks-samwilks@linuxerhan.com
Kurt-Jefferson-kurtjefferson@linuxerhan.com
Sam-Stuart-samstuart@linuxerhan.com
Jane-Stuart-janestuart@linuxerhan.com
Dave-Davis-davedavis@linuxerhan.com
Sam-Patterson-sampatterson@linuxerhan.com
Tom-Jefferson-tomjefferson@linuxerhan.com
Jane-Stuart-janestuart@linuxerhan.com
Maggie-Jefferson-maggiejefferson@linuxerhan.com
Mary-Wilks-marywilks@linuxerhan.com
Neil-Patterson-neilpatterson@linuxerhan.com
Corey-Davis-coreydavis@linuxerhan.com
Steve-Jacobs-stevejacobs@linuxerhan.com
Jane-Jenkins-janejenkins@linuxerhan.com
John-Jacobs-johnjacobs@linuxerhan.com
Neil-Smith-neilsmith@linuxerhan.com
Corey-Wilks-coreywilks@linuxerhan.com
Corey-Smith-coreysmith@linuxerhan.com
Mary-Patterson-marypatterson@linuxerhan.com
Jane-Stuart-janestuart@linuxerhan.com
Travis-Arnold-travisarnold@linuxerhan.com
John-Robinson-johnrobinson@linuxerhan.com
Travis-Arnold-travisarnold@linuxerhan.com
---------------------------------
==========================================
import csv
with open('names2.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file)
with open('new_names2.csv', 'w') as new_file:
csv_writer = csv.writer(new_file, delimiter = '\t')
for line in csv_reader:
csv_writer.writerow(line)
---------------------------------
first_name last_name email
John Doe john-doe@linuxerhan.com
Mary Smith-Robinson maryjacobs@linuxerhan.com
Dave Smith davesmith@linuxerhan.com
Jane Stuart janestuart@linuxerhan.com
Tom Wright tomwright@linuxerhan.com
Steve Robinson steverobinson@linuxerhan.com
Nicole Jacobs nicolejacobs@linuxerhan.com
Jane Wright janewright@linuxerhan.com
Jane Doe janedoe@linuxerhan.com
Kurt Wright kurtwright@linuxerhan.com
Kurt Robinson kurtrobinson@linuxerhan.com
Jane Jenkins janejenkins@linuxerhan.com
Neil Robinson neilrobinson@linuxerhan.com
Tom Patterson tompatterson@linuxerhan.com
Sam Jenkins samjenkins@linuxerhan.com
Steve Stuart stevestuart@linuxerhan.com
Maggie Patterson maggiepatterson@linuxerhan.com
Maggie Stuart maggiestuart@linuxerhan.com
Jane Doe janedoe@linuxerhan.com
Steve Patterson stevepatterson@linuxerhan.com
Dave Smith davesmith@linuxerhan.com
Sam Wilks samwilks@linuxerhan.com
Kurt Jefferson kurtjefferson@linuxerhan.com
Sam Stuart samstuart@linuxerhan.com
Jane Stuart janestuart@linuxerhan.com
Dave Davis davedavis@linuxerhan.com
Sam Patterson sampatterson@linuxerhan.com
Tom Jefferson tomjefferson@linuxerhan.com
Jane Stuart janestuart@linuxerhan.com
Maggie Jefferson maggiejefferson@linuxerhan.com
Mary Wilks marywilks@linuxerhan.com
Neil Patterson neilpatterson@linuxerhan.com
Corey Davis coreydavis@linuxerhan.com
Steve Jacobs stevejacobs@linuxerhan.com
Jane Jenkins janejenkins@linuxerhan.com
John Jacobs johnjacobs@linuxerhan.com
Neil Smith neilsmith@linuxerhan.com
Corey Wilks coreywilks@linuxerhan.com
Corey Smith coreysmith@linuxerhan.com
Mary Patterson marypatterson@linuxerhan.com
Jane Stuart janestuart@linuxerhan.com
Travis Arnold travisarnold@linuxerhan.com
John Robinson johnrobinson@linuxerhan.com
Travis Arnold travisarnold@linuxerhan.com
---------------------------------
==========================================
import csv
with open('new_names2.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file)
for line in csv_reader:
print(line)
---------------------------------
['first_name\tlast_name\temail']
['John\tDoe\tjohn-doe@linuxerhan.com']
['Mary\tSmith-Robinson\tmaryjacobs@linuxerhan.com']
['Dave\tSmith\tdavesmith@linuxerhan.com']
['Jane\tStuart\tjanestuart@linuxerhan.com']
['Tom\tWright\ttomwright@linuxerhan.com']
['Steve\tRobinson\tsteverobinson@linuxerhan.com']
['Nicole\tJacobs\tnicolejacobs@linuxerhan.com']
['Jane\tWright\tjanewright@linuxerhan.com']
['Jane\tDoe\tjanedoe@linuxerhan.com']
['Kurt\tWright\tkurtwright@linuxerhan.com']
['Kurt\tRobinson\tkurtrobinson@linuxerhan.com']
['Jane\tJenkins\tjanejenkins@linuxerhan.com']
['Neil\tRobinson\tneilrobinson@linuxerhan.com']
['Tom\tPatterson\ttompatterson@linuxerhan.com']
['Sam\tJenkins\tsamjenkins@linuxerhan.com']
['Steve\tStuart\tstevestuart@linuxerhan.com']
['Maggie\tPatterson\tmaggiepatterson@linuxerhan.com']
['Maggie\tStuart\tmaggiestuart@linuxerhan.com']
['Jane\tDoe\tjanedoe@linuxerhan.com']
['Steve\tPatterson\tstevepatterson@linuxerhan.com']
['Dave\tSmith\tdavesmith@linuxerhan.com']
['Sam\tWilks\tsamwilks@linuxerhan.com']
['Kurt\tJefferson\tkurtjefferson@linuxerhan.com']
['Sam\tStuart\tsamstuart@linuxerhan.com']
['Jane\tStuart\tjanestuart@linuxerhan.com']
['Dave\tDavis\tdavedavis@linuxerhan.com']
['Sam\tPatterson\tsampatterson@linuxerhan.com']
['Tom\tJefferson\ttomjefferson@linuxerhan.com']
['Jane\tStuart\tjanestuart@linuxerhan.com']
['Maggie\tJefferson\tmaggiejefferson@linuxerhan.com']
['Mary\tWilks\tmarywilks@linuxerhan.com']
['Neil\tPatterson\tneilpatterson@linuxerhan.com']
['Corey\tDavis\tcoreydavis@linuxerhan.com']
['Steve\tJacobs\tstevejacobs@linuxerhan.com']
['Jane\tJenkins\tjanejenkins@linuxerhan.com']
['John\tJacobs\tjohnjacobs@linuxerhan.com']
['Neil\tSmith\tneilsmith@linuxerhan.com']
['Corey\tWilks\tcoreywilks@linuxerhan.com']
['Corey\tSmith\tcoreysmith@linuxerhan.com']
['Mary\tPatterson\tmarypatterson@linuxerhan.com']
['Jane\tStuart\tjanestuart@linuxerhan.com']
['Travis\tArnold\ttravisarnold@linuxerhan.com']
['John\tRobinson\tjohnrobinson@linuxerhan.com']
['Travis\tArnold\ttravisarnold@linuxerhan.com']
---------------------------------
==========================================
import csv
with open('new_names2.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file, delimiter = '\t')
for line in csv_reader:
print(line)
---------------------------------
['first_name', 'last_name', 'email']
['John', 'Doe', 'john-doe@linuxerhan.com']
['Mary', 'Smith-Robinson', 'maryjacobs@linuxerhan.com']
['Dave', 'Smith', 'davesmith@linuxerhan.com']
['Jane', 'Stuart', 'janestuart@linuxerhan.com']
['Tom', 'Wright', 'tomwright@linuxerhan.com']
['Steve', 'Robinson', 'steverobinson@linuxerhan.com']
['Nicole', 'Jacobs', 'nicolejacobs@linuxerhan.com']
['Jane', 'Wright', 'janewright@linuxerhan.com']
['Jane', 'Doe', 'janedoe@linuxerhan.com']
['Kurt', 'Wright', 'kurtwright@linuxerhan.com']
['Kurt', 'Robinson', 'kurtrobinson@linuxerhan.com']
['Jane', 'Jenkins', 'janejenkins@linuxerhan.com']
['Neil', 'Robinson', 'neilrobinson@linuxerhan.com']
['Tom', 'Patterson', 'tompatterson@linuxerhan.com']
['Sam', 'Jenkins', 'samjenkins@linuxerhan.com']
['Steve', 'Stuart', 'stevestuart@linuxerhan.com']
['Maggie', 'Patterson', 'maggiepatterson@linuxerhan.com']
['Maggie', 'Stuart', 'maggiestuart@linuxerhan.com']
['Jane', 'Doe', 'janedoe@linuxerhan.com']
['Steve', 'Patterson', 'stevepatterson@linuxerhan.com']
['Dave', 'Smith', 'davesmith@linuxerhan.com']
['Sam', 'Wilks', 'samwilks@linuxerhan.com']
['Kurt', 'Jefferson', 'kurtjefferson@linuxerhan.com']
['Sam', 'Stuart', 'samstuart@linuxerhan.com']
['Jane', 'Stuart', 'janestuart@linuxerhan.com']
['Dave', 'Davis', 'davedavis@linuxerhan.com']
['Sam', 'Patterson', 'sampatterson@linuxerhan.com']
['Tom', 'Jefferson', 'tomjefferson@linuxerhan.com']
['Jane', 'Stuart', 'janestuart@linuxerhan.com']
['Maggie', 'Jefferson', 'maggiejefferson@linuxerhan.com']
['Mary', 'Wilks', 'marywilks@linuxerhan.com']
['Neil', 'Patterson', 'neilpatterson@linuxerhan.com']
['Corey', 'Davis', 'coreydavis@linuxerhan.com']
['Steve', 'Jacobs', 'stevejacobs@linuxerhan.com']
['Jane', 'Jenkins', 'janejenkins@linuxerhan.com']
['John', 'Jacobs', 'johnjacobs@linuxerhan.com']
['Neil', 'Smith', 'neilsmith@linuxerhan.com']
['Corey', 'Wilks', 'coreywilks@linuxerhan.com']
['Corey', 'Smith', 'coreysmith@linuxerhan.com']
['Mary', 'Patterson', 'marypatterson@linuxerhan.com']
['Jane', 'Stuart', 'janestuart@linuxerhan.com']
['Travis', 'Arnold', 'travisarnold@linuxerhan.com']
['John', 'Robinson', 'johnrobinson@linuxerhan.com']
['Travis', 'Arnold', 'travisarnold@linuxerhan.com']
---------------------------------
==========================================
import csv
with open('names2.csv', 'r') as csv_file:
csv_reader = csv.DictReader(csv_file)
for line in csv_reader:
print(line)
---------------------------------
{'first_name': 'John', 'last_name': 'Doe', 'email': 'john-doe@linuxerhan.com'}
{'first_name': 'Mary', 'last_name': 'Smith-Robinson', 'email': 'maryjacobs@linuxerhan.com'}
{'first_name': 'Dave', 'last_name': 'Smith', 'email': 'davesmith@linuxerhan.com'}
{'first_name': 'Jane', 'last_name': 'Stuart', 'email': 'janestuart@linuxerhan.com'}
{'first_name': 'Tom', 'last_name': 'Wright', 'email': 'tomwright@linuxerhan.com'}
{'first_name': 'Steve', 'last_name': 'Robinson', 'email': 'steverobinson@linuxerhan.com'}
{'first_name': 'Nicole', 'last_name': 'Jacobs', 'email': 'nicolejacobs@linuxerhan.com'}
{'first_name': 'Jane', 'last_name': 'Wright', 'email': 'janewright@linuxerhan.com'}
{'first_name': 'Jane', 'last_name': 'Doe', 'email': 'janedoe@linuxerhan.com'}
{'first_name': 'Kurt', 'last_name': 'Wright', 'email': 'kurtwright@linuxerhan.com'}
{'first_name': 'Kurt', 'last_name': 'Robinson', 'email': 'kurtrobinson@linuxerhan.com'}
{'first_name': 'Jane', 'last_name': 'Jenkins', 'email': 'janejenkins@linuxerhan.com'}
{'first_name': 'Neil', 'last_name': 'Robinson', 'email': 'neilrobinson@linuxerhan.com'}
{'first_name': 'Tom', 'last_name': 'Patterson', 'email': 'tompatterson@linuxerhan.com'}
{'first_name': 'Sam', 'last_name': 'Jenkins', 'email': 'samjenkins@linuxerhan.com'}
{'first_name': 'Steve', 'last_name': 'Stuart', 'email': 'stevestuart@linuxerhan.com'}
{'first_name': 'Maggie', 'last_name': 'Patterson', 'email': 'maggiepatterson@linuxerhan.com'}
{'first_name': 'Maggie', 'last_name': 'Stuart', 'email': 'maggiestuart@linuxerhan.com'}
{'first_name': 'Jane', 'last_name': 'Doe', 'email': 'janedoe@linuxerhan.com'}
{'first_name': 'Steve', 'last_name': 'Patterson', 'email': 'stevepatterson@linuxerhan.com'}
{'first_name': 'Dave', 'last_name': 'Smith', 'email': 'davesmith@linuxerhan.com'}
{'first_name': 'Sam', 'last_name': 'Wilks', 'email': 'samwilks@linuxerhan.com'}
{'first_name': 'Kurt', 'last_name': 'Jefferson', 'email': 'kurtjefferson@linuxerhan.com'}
{'first_name': 'Sam', 'last_name': 'Stuart', 'email': 'samstuart@linuxerhan.com'}
{'first_name': 'Jane', 'last_name': 'Stuart', 'email': 'janestuart@linuxerhan.com'}
{'first_name': 'Dave', 'last_name': 'Davis', 'email': 'davedavis@linuxerhan.com'}
{'first_name': 'Sam', 'last_name': 'Patterson', 'email': 'sampatterson@linuxerhan.com'}
{'first_name': 'Tom', 'last_name': 'Jefferson', 'email': 'tomjefferson@linuxerhan.com'}
{'first_name': 'Jane', 'last_name': 'Stuart', 'email': 'janestuart@linuxerhan.com'}
{'first_name': 'Maggie', 'last_name': 'Jefferson', 'email': 'maggiejefferson@linuxerhan.com'}
{'first_name': 'Mary', 'last_name': 'Wilks', 'email': 'marywilks@linuxerhan.com'}
{'first_name': 'Neil', 'last_name': 'Patterson', 'email': 'neilpatterson@linuxerhan.com'}
{'first_name': 'Corey', 'last_name': 'Davis', 'email': 'coreydavis@linuxerhan.com'}
{'first_name': 'Steve', 'last_name': 'Jacobs', 'email': 'stevejacobs@linuxerhan.com'}
{'first_name': 'Jane', 'last_name': 'Jenkins', 'email': 'janejenkins@linuxerhan.com'}
{'first_name': 'John', 'last_name': 'Jacobs', 'email': 'johnjacobs@linuxerhan.com'}
{'first_name': 'Neil', 'last_name': 'Smith', 'email': 'neilsmith@linuxerhan.com'}
{'first_name': 'Corey', 'last_name': 'Wilks', 'email': 'coreywilks@linuxerhan.com'}
{'first_name': 'Corey', 'last_name': 'Smith', 'email': 'coreysmith@linuxerhan.com'}
{'first_name': 'Mary', 'last_name': 'Patterson', 'email': 'marypatterson@linuxerhan.com'}
{'first_name': 'Jane', 'last_name': 'Stuart', 'email': 'janestuart@linuxerhan.com'}
{'first_name': 'Travis', 'last_name': 'Arnold', 'email': 'travisarnold@linuxerhan.com'}
{'first_name': 'John', 'last_name': 'Robinson', 'email': 'johnrobinson@linuxerhan.com'}
{'first_name': 'Travis', 'last_name': 'Arnold', 'email': 'travisarnold@linuxerhan.com'}
---------------------------------
==========================================
import csv
with open('names2.csv', 'r') as csv_file:
csv_reader = csv.DictReader(csv_file)
for line in csv_reader:
print(line['email'])
---------------------------------
john-doe@linuxerhan.com
maryjacobs@linuxerhan.com
davesmith@linuxerhan.com
janestuart@linuxerhan.com
tomwright@linuxerhan.com
steverobinson@linuxerhan.com
nicolejacobs@linuxerhan.com
janewright@linuxerhan.com
janedoe@linuxerhan.com
kurtwright@linuxerhan.com
kurtrobinson@linuxerhan.com
janejenkins@linuxerhan.com
neilrobinson@linuxerhan.com
tompatterson@linuxerhan.com
samjenkins@linuxerhan.com
stevestuart@linuxerhan.com
maggiepatterson@linuxerhan.com
maggiestuart@linuxerhan.com
janedoe@linuxerhan.com
stevepatterson@linuxerhan.com
davesmith@linuxerhan.com
samwilks@linuxerhan.com
kurtjefferson@linuxerhan.com
samstuart@linuxerhan.com
janestuart@linuxerhan.com
davedavis@linuxerhan.com
sampatterson@linuxerhan.com
tomjefferson@linuxerhan.com
janestuart@linuxerhan.com
maggiejefferson@linuxerhan.com
marywilks@linuxerhan.com
neilpatterson@linuxerhan.com
coreydavis@linuxerhan.com
stevejacobs@linuxerhan.com
janejenkins@linuxerhan.com
johnjacobs@linuxerhan.com
neilsmith@linuxerhan.com
coreywilks@linuxerhan.com
coreysmith@linuxerhan.com
marypatterson@linuxerhan.com
janestuart@linuxerhan.com
travisarnold@linuxerhan.com
johnrobinson@linuxerhan.com
travisarnold@linuxerhan.com
---------------------------------
==========================================
import csv
with open('names2.csv', 'r') as csv_file:
csv_reader = csv.DictReader(csv_file)
with open('new_names2.csv', 'w') as new_file:
fieldnames = ['first_name', 'last_name', 'email']
csv_writer = csv.DictWriter(new_file, fieldnames = fieldnames, delimiter = '\t')
csv_writer.writeheader()
for line in csv_reader:
csv_writer.writerow(line)
---------------------------------
first_name last_name email
John Doe john-doe@linuxerhan.com
Mary Smith-Robinson maryjacobs@linuxerhan.com
Dave Smith davesmith@linuxerhan.com
Jane Stuart janestuart@linuxerhan.com
Tom Wright tomwright@linuxerhan.com
Steve Robinson steverobinson@linuxerhan.com
Nicole Jacobs nicolejacobs@linuxerhan.com
Jane Wright janewright@linuxerhan.com
Jane Doe janedoe@linuxerhan.com
Kurt Wright kurtwright@linuxerhan.com
Kurt Robinson kurtrobinson@linuxerhan.com
Jane Jenkins janejenkins@linuxerhan.com
Neil Robinson neilrobinson@linuxerhan.com
Tom Patterson tompatterson@linuxerhan.com
Sam Jenkins samjenkins@linuxerhan.com
Steve Stuart stevestuart@linuxerhan.com
Maggie Patterson maggiepatterson@linuxerhan.com
Maggie Stuart maggiestuart@linuxerhan.com
Jane Doe janedoe@linuxerhan.com
Steve Patterson stevepatterson@linuxerhan.com
Dave Smith davesmith@linuxerhan.com
Sam Wilks samwilks@linuxerhan.com
Kurt Jefferson kurtjefferson@linuxerhan.com
Sam Stuart samstuart@linuxerhan.com
Jane Stuart janestuart@linuxerhan.com
Dave Davis davedavis@linuxerhan.com
Sam Patterson sampatterson@linuxerhan.com
Tom Jefferson tomjefferson@linuxerhan.com
Jane Stuart janestuart@linuxerhan.com
Maggie Jefferson maggiejefferson@linuxerhan.com
Mary Wilks marywilks@linuxerhan.com
Neil Patterson neilpatterson@linuxerhan.com
Corey Davis coreydavis@linuxerhan.com
Steve Jacobs stevejacobs@linuxerhan.com
Jane Jenkins janejenkins@linuxerhan.com
John Jacobs johnjacobs@linuxerhan.com
Neil Smith neilsmith@linuxerhan.com
Corey Wilks coreywilks@linuxerhan.com
Corey Smith coreysmith@linuxerhan.com
Mary Patterson marypatterson@linuxerhan.com
Jane Stuart janestuart@linuxerhan.com
Travis Arnold travisarnold@linuxerhan.com
John Robinson johnrobinson@linuxerhan.com
Travis Arnold travisarnold@linuxerhan.com
---------------------------------
==========================================
import csv
with open('names2.csv', 'r') as csv_file:
csv_reader = csv.DictReader(csv_file)
with open('new_names2.csv', 'w') as new_file:
fieldnames = ['first_name', 'last_name']
csv_writer = csv.DictWriter(new_file, fieldnames = fieldnames, delimiter = '\t')
csv_writer.writeheader()
for line in csv_reader:
del line['email']
csv_writer.writerow(line)
---------------------------------
first_name last_name
John Doe
Mary Smith-Robinson
Dave Smith
Jane Stuart
Tom Wright
Steve Robinson
Nicole Jacobs
Jane Wright
Jane Doe
Kurt Wright
Kurt Robinson
Jane Jenkins
Neil Robinson
Tom Patterson
Sam Jenkins
Steve Stuart
Maggie Patterson
Maggie Stuart
Jane Doe
Steve Patterson
Dave Smith
Sam Wilks
Kurt Jefferson
Sam Stuart
Jane Stuart
Dave Davis
Sam Patterson
Tom Jefferson
Jane Stuart
Maggie Jefferson
Mary Wilks
Neil Patterson
Corey Davis
Steve Jacobs
Jane Jenkins
John Jacobs
Neil Smith
Corey Wilks
Corey Smith
Mary Patterson
Jane Stuart
Travis Arnold
John Robinson
Travis Arnold
---------------------------------