I have a dataframe named :- df_explode
inputdataframe
I have a list of strings " myList_groupby
".
myList_groupby = ["domain","tag_name","tag_hierarchy","html_attributes","extension","xyz"]
I want to generate a new column named "combined" in df_explode
,whose elements will be a string concatenation for all the columns whose header matches with strings in myList_groupby
list.(is in myList_groupby
)
Output dataframe :-
我认为,需要通过子集过滤列,并呼吁join
每行:
df['new'] = df[myList_groupby].apply('_'.join, axis=1)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.