python 2.7 - Loop through csv with Pandas, specific column -
with csv module, loop through rows execute logic:
import csv open("file.csv", "r") csv_read: r = csv.reader(csv_read, delimiter = ",") next(r, none) #skip headers first row row in rows: #logic here i'm new pandas, , want execute same logic, using second column only in csv input loop.
import pandas pd pd.read_csv("file.csv", usecols=[1]) assuming above correct, should here execute logic based on cells in column 2?
i want use cell values in column 2 input web crawler. takes each result , inputs search term on webpage, , scrapes data webpage. there way grab each cell value in array rather whole array @ same time?
basically pandas equivalent of code this:
import pandas pd df = pd.read_csv("file.csv", usecols=[1]) so passing usecols=[1] load second column, see docs.
now assuming column has name 'url' doesn't matter can like:
def crawl(x): #do df.apply(crawl) so in principle above crawl each url in column value @ time.
edit
you can pass param axis=1 apply process each row rather entire column:
df.apply(crawl, axis=1)
Comments
Post a Comment