[英]How in Pandas Dataframe and Python can extract the specific text string after a given word?
我想从此 dataframe 中提取“文本:.....”范围内的文本,并使用该值创建另一列。
这是我的 Pandas Dataframe
issues_df['new_column'] = issues_df['fields.description.content'].apply(lambda x: x['text'])
但是,它返回以下错误:
issues_df['new_column'] = issues_df['fields.description.content'].apply(lambda x: x['text'])
TypeError: Object 'float' is not writable.
有什么建议么?
提前致谢。
问题是列中的NaN
,您可以尝试.str
访问器
issues_df['new_column'] = issues_df['fields.description.content'].str[0].str['content'].str[0].str['text']
对于相当高效的json_normalize
来说,这可能是一项很好的任务:
df['new_column'] = pd.json_normalize(
df['fields.description.content'], 'content'
)['text']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.