简体   繁体   English

如何将列的空白从一个数据框填充到另一个数据框?

[英]how to fill blank of column from one data frame to another?

i have a 2 dataframe, i wanted to fill the ID column blank with help first column ID.我有一个 2 dataframe,我想在第一列 ID 的帮助下填写 ID 列空白。 The data is not Identical the second data is having less number of entry.数据不相同,第二个数据的条目数较少。 And I have to find the id values with respect to the C_name column.而且我必须找到与 C_name 列相关的 id 值。 If C_Name and I'd of 1st data is equal to the 2rd data value the value from 1 data should come to 2 data frame如果第一个数据的 C_Name 和 I 等于第二个数据值,则来自 1 个数据的值应该来自 2 个数据帧

C_Name  ID  item ID
Ad  ADV01   ADV001
NC  899 NC01
NC  899 NC01
Med 14996   0-A
Bank    20668   BNK002
Light   LIG01   LIG01
Light   LIG01   LIG03
Light   LIG01   LIG03
Light   LIG01   LIG03
Ad  ADV01   AD01
Ivar's  IVARS01 I01
Ad  ADV01   AD01
Light   LIG01   LIG03
OneNet  ONT01   ONENET001
Light   LIG01   LIG03
Tri CAL01   201-TP
Tri CAL01   201-SPK
Tri CAL01   201-CHI
Light   LIG01   2059
Light   LIG01   2059
Light   LIG01   2059
Light   LIG01   2059
Light   LIG01   2059
Distribution    DMSI01  2052

second data第二数据

C_Name  ID  item ID
Ad  ADV01   ADV001
NC  899 NC01
NC      NC01
Med 14996   0-A
Bank    20668   BNK002
Light   LIG01   LIG01
Light       LIG03
Light       LIG03
Light       LIG03
Ad  ADV01   AD01
Ivar's  IVARS01 I01
Ad  ADV01   AD01
Light   LIG01   LIG03
OneNet  ONT01   ONENET001
Light   LIG01   LIG03
Tri CAL01   201-TP
Tri     201-SPK
Tri     201-CHI
Light   LIG01   2059
Light       2059
Light       2059
Light       2059
Light       2059
Distribution    DMSI01  2052

how should i do it?我该怎么做?

You can use series.update(other) as您可以使用series.update(other)作为

df2.ID.upadte(df1.ID)

Careful with小心翼翼

  1. Pandas aligns the indexes of both series, so if there is not a significant index defined it wil work with the default RangeIndex. Pandas 对齐两个系列的索引,因此如果没有定义重要的索引,它将使用默认的 RangeIndex。 If this is the case and dfs don't the same amount of rows in the same order then you will get unexpected results.如果是这种情况,并且 dfs 的行数不同,那么您将得到意想不到的结果。
  2. All non-NA values from df1 will be copied to df2, if df2 already had a value it will be overwritten df1 中的所有非 NA 值都将被复制到 df2,如果 df2 已经有一个值,它将被覆盖

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 基于部分字符串匹配从另一个 dataframe 填充一个数据框列 - Based on Partial string Match fill one data frame column from another dataframe 在pandas数据框中将索引从一列移动到另一列 - Moving index from one column to another in pandas data frame 将一个数据框中的一列添加到另一个具有不相等行的列 - Adding a column from one data frame to another with unequal rows MSSQL:如果有条件,则使用另一列中的值有条件地填充该列 - MSSQL: Conditionally Fill in Column With Value From Another Column If Blank 从一个数据框列到另一个数据框列的字符串匹配 - String matching from one data frame column to another data frame column 如何根据行/列名称将一个数据框的列附加为另一个数据框的行? - How to append column of one data frame as row of another data frame based on row/column name? pandas:如何根据列值在一个数据帧中从另一个数据帧中 append 行? - pandas: How can I append rows in one data frame from another based on column values? 如何检查一列中的值是否等于另一列数据框中的值 - How to check if value from one column is equal to value in another columns data-frame 用熊猫数据框中另一列的值在多列中填充Na - Fill Na in multiple columns with values from another column within the pandas data frame 当两者在另一列中共享相等的值时,如何用同一列中的值填充数据框列中的 nan 值? 例如:Where 子句 - How to fill nan values in a data frame's column with a value from the same column when both share the equal value in another column? Ex: Where clause
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM