I tried to loop for url_data. url_data is an array of strings. I get an IndexError that reads:
keywords[i]=urlparse.urlparse(url_data[i])
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
My code:
import os
import csv
import numpy as np
import pandas
import urlparse
from numpy import genfromtxt
os.chdir("C:\Users\EDAWES01\Desktop\Cookie profiling")
data = pandas.read_csv('activity_url.csv', delimiter=';')
data_read=np.array(data)
quantity = data_read[:, 2]
url_data = data_read[quantity==1][:,1]
url_data #extract URL data
keywords=[]
for i in url_data:
keywords[i]=urlparse.urlparse(url_data[i])
keywords[i]=keywords[2] #this is the path element
keywords[i]=keywords[i].split("/")
keywords
keywordsis initialized to an empty list. So there are no valid indices. The loop tries to useias an index, multiple times, but (1)iapparently isn't an integer and (2) even if it were, it would be out of range since they're all out of range for an empty list.keywordsis a error. But the error message is abouturl_data[i].url_dataandiarestr.str[str]won't work