pandas

set df to value between tuple

set df to value between tuple Question: i would like to set a df value between two values x_lim(0,2) to True. I would like to get a df that looks like this: x | y | z 0 | 7 | True 1 | 3 | True 2 | 4 | True 3 | 8 …

Total answers: 2

Select column containing several value with range of number in pandas

Select column containing several value with range of number in pandas Question: If I have a dataframe ` A Variant&Price Qty AAC 7:124|25: 443 1 AAD 35:|35: 1 AAS 32:98|3:40 1 AAG 2: |25: 1 AAC 25:443|26:344 1 and I want to get variant which has one of its values is below 7 A Variant&Price …

Total answers: 2

Remove empty strings from a list of strings on each row in a pandas dataframe

Remove empty strings from a list of strings on each row in a pandas dataframe Question: I have a pandas dataframe and one of the columns contains a list of strings e.g: [”, ‘Hello’, ‘The house is warm’, ”, ‘What time is it’] The strings are different for each row of the dataframe but all …

Total answers: 1

group column values with difference of 3(say) digit in python

group column values with difference of 3(say) digit in python Question: I am new in python, problem statement is like we have below data as dataframe df = pd.DataFrame({‘Diff’:[1,1,2,3,4,4,5,6,7,7,8,9,9,10], ‘value’:[x,x,y,x,x,x,y,x,z,x,x,y,y,z]}) Diff value 1 x 1 x 2 y 3 x 4 x 4 x 5 y 6 x 7 z 7 x 8 x 9 …

Total answers: 1

pandas/regex: Remove the string after the hyphen or parenthesis character (including) carry string after the comma in pandas dataframe

pandas/regex: Remove the string after the hyphen or parenthesis character (including) carry string after the comma in pandas dataframe Question: I have a dataframe contains one column which has multiple strings separated by the comma, but in this string, I want to remove all matter after hyphen (including hyphen), main point is after in some …

Total answers: 2

count the number of values in data frame's column that exist in another data frame's column

count the number of values in data frame's column that exist in another data frame's column Question: I have two data frames: df1: Index Date 0 2016-03-21 20:10:00 1 2016-03-22 21:09:00 2 2016-05-03 17:05:00 df2: Index Date 0 2016-03-21 20:10:00 1 2016-03-21 21:00:00 2 2016-03-22 21:09:00 3 2016-05-03 17:05:00 4 2017-06-01 16:10:00 There’s probably a …

Total answers: 2

Create new column using custom function pandas df error

Create new column using custom function pandas df error Question: I want to create a new column which gives every row a category based on their value in one specific column. Here is the function: def assign_category(df): if df[‘AvgVAA’] >= -4: return ‘Elite’ elif df[‘AvgVAA’] <= -4 and df[‘AvgVAA’] > -4.5: return ‘Above Average’ elif …

Total answers: 1

'DataFrame' object does not support item assignment

'DataFrame' object does not support item assignment Question: I imported a df into Databricks as a pyspark.sql.dataframe.DataFrame. Within this df I have 3 columns (which I have verified to be strings) that I wish to concatenate. I have tried to use a simple "+" function first, eg. df["fullname"] = df["firstname"] + df["middlename"] + df["lastname"] But …

Total answers: 2

Keep observations with two or more consecutive years of data by group

Keep observations with two or more consecutive years of data by group Question: I have a dataset consisting of directorid, match_id, and calyear. I would like to keep only observations by director_id and match_id that have at least 2 consecutive years of data. I have tried a few different ways to do this, and haven’t …

Total answers: 1