apply

I am getting this error: TypeError: '<' not supported between instances of 'str' and 'float'

I am getting this error: TypeError: '<' not supported between instances of 'str' and 'float' Question: I have this table that in which I am comparing list of articles (Article_body) with 4 baseline articles using cosine similarity: Article_body articleScores1 articleScores2 articleScores3 articleScores4 articleScores5 a***** 0.6 0.2 0.7 0.9 0.2 a***** 0.3 0.8 0.1 0.5 0.1 …

Total answers: 1

Python Replace existing column value in df based on separate lookup Code/Value (df) KeyError on columns.get_loc

Python Replace existing column value in df based on separate lookup Code/Value (df) KeyError on columns.get_loc Question: ** Problem ** Replace existing column value in destination data frame based on separate lookup type operations to match Code/Value column in another separate source data frame, and update, e.g., replace text in destination data frame column with …

Total answers: 1

Detecting Keys in a Column of Strings

Detecting Keys in a Column of Strings Question: I have a dictionary with key and value pairs. I also have a data frame with a column containing strings that contain the various keys. If a key appears in the column in the data frame, I’d like to append the corresponding value in the adjacent column …

Total answers: 1

Apply a function on a single element of a tuple

Apply a function on a single element of a tuple Question: With a direct example it would be easier to understand data = [(1995, 50.28), (1996, 28.52)] result = [(1995, 50), (1996, 29)] I would like to apply a transformation only on the second number of each tuple (50.28 and 28.52). I saw the map() …

Total answers: 5

How to wrap cell value in a dict maintaining value without using apply

How to wrap cell value in a dict maintaining value without using apply Question: I have a Pandas dataframe with a colum with some string and some NaN values. df[‘column’] = [‘a’, ‘b’, NaN, ‘c’] What I want to achieve is to transform the value in dicts, maintaining the original value: df[‘column’] = [{‘key’: ‘a’}, …

Total answers: 1

Find shapes of dataframes inside lambda functions

Find shapes of dataframes inside lambda functions Question: I have the following dataframe with pairs of strings in tuples d = {‘value’: [[‘Red’, ‘Blue’], [‘Blue’, ‘Yellow’], [‘Blue’, ‘Yellow’], [‘Yellow’, ‘Orange’], [‘Green’, ‘Purple’], [‘Purple’, ‘Yellow’], [‘Yellow’, ‘Red’], [‘Violet’, ‘Blue’], [‘Blue’, ‘Green’], [‘Green’, ‘Red’], [‘Red’, ‘Brown’], [‘Blue’, ‘Green’]]} df = pd.DataFrame(data = d) And I want to …

Total answers: 1

Find list of indices before specific value in column for each unique id

Find list of indices before specific value in column for each unique id Question: I have dataframe like this: id | date | status ________________________ … … … 1 |2020-01-01 | reserve 1 |2020-01-02 | sold 2 |2020-01-01 | free 3 |2020-01-03 | reserve 3 |2020-01-25 | signed 3 |2020-01-30 | sold … … … …

Total answers: 1

Apply lambda involving 2 dataframes in pandas

Apply lambda involving 2 dataframes in pandas Question: I would like to select data in df2 based on time intervals in df1: df1: ID Start End col1 col2 23468 2011-01-03 01:01:03 2011-01-03 01:04:05 10 a 23468 2011-01-15 08:20:00 2011-01-18 01:01:01 50 b 23468 2011-02-03 01:07:20 2011-02-08 12:00:03 150 a 33525 2011-02-03 01:07:19 2011-02-06 12:00:03 10 …

Total answers: 1