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


You talk about variables, but is it not a dataframe, filtered_df? Which is the variable that you're mentioning, the dataframe itself?

What I did so far was only:

Import some of the libraries needed
import pandas as pd
import numpy as np
import re
from IPython.display import display
Import the file
xlsx = pd.ExcelFile("excelfile.xlsx")
Read each of the tabs in the file
df1 = pd.read_excel(xlsx, "Tab1")
df2 = pd.read_excel(xlsx, "Tab2")
df3 = pd.read_excel(xlsx, "Tab3")
Concatenate the three tabs from the excel file and create a dataframe with the data
dataframe = [df1,df2,df3]
df = pd.concat(dataframe, ignore_index=True)
df.head()


Then I'm filtering the data contained in the dataframe
[python]
df_filtered = df[(df['Destination'].str.contains("website.com",regex=True)==True)&(df['Source'].str.contains("website.com",regex=True)==True)&(df['Type']== "AHREF")]
df_filtered.head(2)
Then I'm trying to created the categories in the filtered dataframe
def categories(Source):
    if '/string1' in Source: return 'Category 1'
    elif '/string1' in Source: return 'Category 2'
    else: return 'other'
 
df_filtered.loc[:, 'Category'] = df_filtered.Source.apply(categories)
Which course could give me some understanding of all those rules? I'm reading "Python for Data Analysis" but it is hard to remember all of this. I guess I need to keep practising.

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 2,410 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