Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Classify URLs
#1
Hi there,

I'm starting learning Python to be able to replace excel and be more efficient. I have a dataframe with a column called 'Source' which contains a list of URLs. I want to create a new column called 'Category' which will have the category of the URL. The category will be based on the strings inside the URL.

When I look for this type of URL categorisation, it seems that most of the people use more difficult and advance systems. Is it not possible to use a if function for this purpose?

I have tried this code but it seems that the syntax is not right. Any advice on where to look to find out simple ways to classify URLs?

category = def categories (df) = {
    if (df['Source'].str.contains("/string1",regex=True)): 'Category 1',
    elif (df['Source'].str.contains("/string2",regex=True)): 'Category 2',
    else: other 
}
df['Category']= category
df.head()
Many thanks!
Reply


Messages In This Thread
Classify URLs - by Newlearner - Aug-11-2019, 11:02 AM
RE: Classify URLs - by boring_accountant - Aug-11-2019, 04:54 PM
RE: Classify URLs - by Newlearner - Aug-11-2019, 06:32 PM
RE: Classify URLs - by boring_accountant - Aug-11-2019, 08:27 PM
RE: Classify URLs - by Newlearner - Aug-12-2019, 07:40 PM
RE: Classify URLs - by boring_accountant - Aug-13-2019, 12:18 AM
RE: Classify URLs - by Newlearner - Aug-13-2019, 05:58 PM
RE: Classify URLs - by boring_accountant - Aug-14-2019, 02:43 AM
RE: Classify URLs - by Newlearner - Aug-14-2019, 11:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there a Python text mining script to classify text with multiple classifications? Endearment 0 1,841 Oct-21-2019, 07:50 PM
Last Post: Endearment

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020