How to count the occurrences of a column's value in a column of lists?

Advertisements Consider the following dataframe: column_of_lists scalar_col 0 [100, 200, 300] 100 1 [100, 200, 200] 200 2 [300, 500] 300 3 [100, 100] 200 The desired output would be a Series, representing how many times the scalar value of scalar_col appears inside the list column. So, in our case: 1 # 100 appears once… Read More How to count the occurrences of a column's value in a column of lists?

Convert pandas series strings to numbers

Advertisements `Following series, contains result as string of lists with values either PASS or FAIL. Input:- result "[‘PASS’,’FAIL’]" "[‘PASS’,’FAIL’,’PASS’,’FAIL’]" "[‘FAIL’,’FAIL’]" Output: result 1 1 0 If any row has at-least one PASS as value then return 1 else return 0 Input:- result "[‘PASS’,’FAIL’]" "[‘PASS’,’FAIL’,’PASS’,’FAIL’]" "[‘FAIL’,’FAIL’]" >Solution : If there are lists use in statement: df[‘result’]… Read More Convert pandas series strings to numbers

multiple series appended in a list using df.iterrows. How do I convert it into a dataframe?

Advertisements I would like to know how to covert multiple series objects in list into a dataframe. import pandas as pd data = { "firstname": ["Sally", "Mary", "John"], "age": [50, 40, 30], "lastname" : ["a1", "b1", "c1"], } df = pd.DataFrame(data) tmp_list = list() for idx, row in df.iterrows(): tmp_list.append(row) My tmp_list looks like this.… Read More multiple series appended in a list using df.iterrows. How do I convert it into a dataframe?

Changing the format of a column of data in a Pandas Series

Advertisements I would like to change the format of the returned dates from this: listOfDates = df2[‘TradeDate’].drop_duplicates().reset_index(drop=True) print(listOfDates) 0 2022-02-02 1 2022-02-08 2 2022-05-01 3 2022-05-06 4 2022-06-05 5 2022-06-17 6 2022-07-30 7 2022-08-03 8 2022-10-10 9 2022-11-18 Name: TradeDate, dtype: datetime64[ns] to this: listOfDates = df2[‘TradeDate’].drop_duplicates().reset_index(drop=True) print(listOfDates) 0 20220202 1 20220208 2 20220501 3… Read More Changing the format of a column of data in a Pandas Series