I have two example csv files to make it easier, where csvexample.csv looks like this:
ID Text
1 'goodmorning'
2 'goodafternoon'
3 'goodevening'
The csvexample1.csv file looks like this:
Day Month
17 'Feb'
18 'Mar'
19 'May'
I want the first column of the first file and the second column of the second file to be added to one singular list. So far I have the following code:
import csv
from collections import defaultdict
columns = defaultdict(list)
with open('csvexample.csv') as f, open('csvexample1.csv') as a:
reader=csv.reader(f)
reader1=csv.reader(a)
next(reader)
next(reader1)
for row in reader:
for(i,v) in enumerate(row):
columns[i].append(v)
print (columns[0])
for row in reader1:
for (b,c) in enumerate(row):
columns[b].append(c)
print (columns[1])
This gives me the following outcome:
['1','2','3']
['Goodmorning', 'Goodafternoon', 'Goodevening ', 'Feb', 'Mar', 'May']
I'm quite new to python and I kind of do understand why I'm getting this result, but I am not sure how to fix it. I want the outcome to be:
['1', '2', '3', 'Feb', 'Mar', 'May'] but nothing I try seems to be working.