[英]Replacing null values of a dataframe with a sub-string of another column value
I'm trying to replaced null values of a dataframe with a value of another column value.我正在尝试用另一个列值的值替换 dataframe 的 null 值。
Product name | Brand | Rate | Qty |
--------------|---------|------|------|
samsung note | Null | 5 | 1 |
Nokia Lumia | Nokia | 2 | 2 |
One Plus 8 | Null | 3 | 3 |
How to get this output?如何获得这个 output? I want to fill the missing value on Brand based on value on keyword in Product Name .我想根据Product Name中的关键字值填充Brand上的缺失值。 The result I need is like:我需要的结果是:
if value in Product Name = Samsung Note then value in Brand= "samsung"
if value in Product Name = One Plus 8 then value in Brand= "One Plus"
Product name | Brand | Rate | Qty |
--------------|---------|------|------|
samsung note | Samsung| 5 | 1 |
Nokia Lumia | Nokia | 2 | 2 |
One Plus 8 | One Plus| 3 | 3 |
I would try something like this:我会尝试这样的事情:
df['column_you_want'] = df.apply(lambda row: row['column_you_want'] if row['column_you_want'] else row['column_string'][start_substring:end_substring])
Let me know if it works:)让我知道它是否有效:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.