1
os.chdir("C:\Users\EDAWES01\Desktop\Cookie profiling")
data = pandas.read_csv('activity_url.csv', delimiter=';')
data_read=np.array(data)
quantity = data_read[0:, 2]
other_data = data_read[0:, 1]
x="http"
url_data = data_read[np.logical_and(quantity==1, any(x in other_data)][:,1] #extraction

I get this error:

TypeError: 'bool' object is not iterable

1 Answer 1

1

You can use iloc for selecting and boolean indexing with str.contains:

import pandas as pd
import io

temp=u"""0;1;2
0;http;1
5;http1;0
8;aa2;7
9;fffhttp;1"""
#after testing replace io.StringIO(temp) to filename
data = pd.read_csv(io.StringIO(temp), sep=";")
print (data)
   0        1  2
0  0     http  1
1  5    http1  0
2  8      aa2  7
3  9  fffhttp  1

x="http"
url_data = data[(data.iloc[:, 2] == 1) & (data.iloc[:, 1].str.contains(x))]
print (url_data)
   0        1  2
0  0     http  1
3  9  fffhttp  1

print (url_data.iloc[:,1])
0       http
3    fffhttp
Name: 1, dtype: object
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for upvoting - now you can upvote each answer in StackOverflow, what is helful for you. ;) Nice day!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.