filter a DataFrame using complete word only

filter a DataFrame using complete word only Problem Description: I have a large DataFrame (named: complete) of data (only two columns). I want to filter it using complete words only, instead of substrings. Ex: complete dataframe: comment sentiment fast running 0.9 heavily raining 0.5 in the house 0.1 coming in 0.0 rubbing it -0.5 if … Read more

Remove duplicates based on combination of two columns in Pandas

Remove duplicates based on combination of two columns in Pandas Problem Description: I need to delete duplicated rows based on combination of two columns (person1 and person2 columns) which have strings. For example person1: ryan and person2: delta or person 1: delta and person2: ryan is same and provides the same value in messages column. … Read more

Pandas: Replace and remove character in columns

Pandas: Replace and remove character in columns Problem Description: I have a dataframe in pandas, in this format: I need to perform formatting on my dataframe that is larger than this, generally speaking only on the ‘CTe’ column CTe = ["1221-2","12321-45","123-3"] UF = [‘A’,’B’,’C’] df = pd.DataFrame( data = zip(CTe,UF), columns=["CTe","UF"]) And I would like … Read more

How to solve the value error received while working with this dictionary?

How to solve the value error received while working with this dictionary? Problem Description: I have a dataframe from which the columns are grouped as: {(a, b, c): [(‘d’, e, f)]} with this command: dct = df.groupby([‘a’,’b’,’c’])[[‘d’,’e’,’f’]].apply( lambda g: list(map(tuple, g.values.tolist()))).to_dict() After this, I apply: dct = {k: dict(v) for k,v in dct.items()} which gives … Read more

How can I get BeautifulSoup running within another for loop?

How can I get BeautifulSoup running within another for loop? Problem Description: I’m currently trying to put together an article scraper for a website, but I’m running into an issue that I don’t know how to solve. This is the code: import newspaper from newspaper import Article import pandas as pd import datetime from datetime … Read more

How can I get BeautifulSoup running within another for loop?

How can I get BeautifulSoup running within another for loop? Problem Description: I’m currently trying to put together an article scraper for a website, but I’m running into an issue that I don’t know how to solve. This is the code: import newspaper from newspaper import Article import pandas as pd import datetime from datetime … Read more

Pandas filter MultiIndex on part of MultiIndex using .loc

Pandas filter MultiIndex on part of MultiIndex using .loc Problem Description: I want to filter a DataFrame using only 2 levels of a 3-level MultiIndex. Is there a way cant find a way to do that with .loc? The only way I managed to do that is the following: df=pd.DataFrame(index=pd.MultiIndex.from_tuples([(1,’a’,’x’) ,(1,’a’,’y’) ,(1,’b’,’z’) ,(1,’b’,’x’) ,(2,’c’,’y’) ,(2,’c’,’z’) … Read more

Python/Pandas – Check if multiple columns has any of three items in a list

Python/Pandas – Check if multiple columns has any of three items in a list Problem Description: I am creating a binary target variable that is 1 if any of these select columns (Current, Month1, Month2, Month3, Month4, Month5, Month6) has any number of these three strings (‘Item1’, ‘Item2’, ‘Item3’). If none of these columns have … Read more

We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Reject