pandas-apply

Why is this apply() custom function is slower in Polars than in Pandas

Why is this apply() custom function is slower in Polars than in Pandas Question: I ran the following in a Jupyter Notebook and was disappointed that similar Pandas code is faster. Hoping someone can show a smarter approach in Polars. POLARS VERSION def cleanse_text(sentence): RIGHT_QUOTE = r"(u2019)" sentence = re.sub(RIGHT_QUOTE, "’", sentence) sentence = re.sub(r" …

Total answers: 1

Get correlation per groupby/apply in Python Polars

Get correlation per groupby/apply in Python Polars Question: I have a pandas DataFrame df: d = {‘era’: ["a", "a", "b","b","c", "c"], ‘feature1’: [3, 4, 5, 6, 7, 8], ‘feature2’: [7, 8, 9, 10, 11, 12], ‘target’: [1, 2, 3, 4, 5 ,6]} df = pd.DataFrame(data=d) And I want to apply a correlation between the feature_cols …

Total answers: 1

How do I keep values based on dataframe values?

How do I keep values based on dataframe values? Question: I have the following dataframe. ID path1 path2 path3 1 12 NaN NaN 1 1 5 NaN 1 2 NaN ” 1 2 4 111 2 123 NaN NaN 3 11 25 NaN 3 1 NaN NaN 3 21 34 NaN 3 NaN NaN NaN …

Total answers: 1

Pandas : Concat rows of a dataframe with same index to form custom string in pairs

Pandas : Concat rows of a dataframe with same index to form custom string in pairs Question: Say I have a dataframe df = pd.DataFrame({‘colA’ : [‘ABC’, ‘JKL’, ‘STU’, ‘123’], ‘colB’ : [‘DEF’, ‘MNO’, ‘VWX’, ‘456’], ‘colC’ : [‘GHI’, ‘PQR’, ‘YZ’, ‘789’],}, index = [0,0,1,1]) colA colB colC 0 ABC DEF GHI 0 JKL MNO …

Total answers: 3

python pandas groupby/apply: what exactly is passed to the apply function?

python pandas groupby/apply: what exactly is passed to the apply function? Question: Python newbie here. I’m trying to understand how the pandas groupby and apply methods work. I found this simple example, which I paste below: import pandas as pd ipl_data = {‘Team’: [‘Riders’, ‘Riders’, ‘Devils’, ‘Devils’, ‘Kings’, ‘kings’, ‘Kings’, ‘Kings’, ‘Riders’, ‘Royals’, ‘Royals’, ‘Riders’], …

Total answers: 4