Concatenate results of `apply` in pandas

I would like to apply a function to each element/row of a pandas Series/DataFrame and concatenate/stack the results into a single DataFrame. E.g., I may start with a Series s = pd.Series(["a", "b,c", "d,e,f"]), and I would like to obtain as a final result res = pd.Series(["a", "b", "c", "d", "e", "f"]) A slow way… Read More Concatenate results of `apply` in pandas

Convert pandas series strings to numbers

`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?

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. [firstname… 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

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 20220506… Read More Changing the format of a column of data in a Pandas Series