Reputation: 319
I have a csv file with Reddit ID. In first column there may be 2-6 ids but in second column there is always 2 IDs. I have to write a script so that i can fetch the posts from IDs for the both column.
Your help will be much appreciated.
Upvotes: 0
Views: 134
Reputation: 64
So first of all you need to read that file.
import csv
with open('yourfilename.csv', mode ='r') as file:
csvFile = csv.reader(file)
Taken from here
Next you would want to split each column to a list, so that you can scrape multiple ids
idList = []
for line in csvFile: # loop each line
for columns in line: # loop each column
for element in columns.split(' '): # loop each element
idList.append(element)
print(idList)
Taken from here
Upvotes: 2