[英]What is the most pythonic way to combine multiple string columns to create a new Pandas series?
I have a large dataframe with each row containing various amounts of text/string data (song lyrics that were webscraped and then split by line '\\n').我有一个大数据框,每行包含不同数量的文本/字符串数据(被网络抓取然后按行“\\n”分割的歌词)。 Some columns have None values because of this.
因此,某些列具有 None 值。 I'd like to combine all the columns that do have a value into 1 column for each row.
我想将所有具有值的列合并为每行的 1 列。 I've attached a screenshot so you can see what I'm working with(profanity censored).
我附上了一个截图,所以你可以看到我在做什么(亵渎审查)。
为了避免 NAs,这里有一种使用agg
的方法:
df_with_line_sentences.agg(lambda x: ' '.join(i for i in x if not pd.isna(i)), axis=1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.