简体   繁体   English

如何在数据框的每一行的列中添加特定值

[英]How to add specific value in column in in every row in dataframe

here i am trying add (EA) in every record for column 1 is it possible to save value in column 1 like 1.0 Each(EA) followed by 0.0 / 0.001 (EA)... 在这里我正在尝试在第1列的每条记录中添加(EA),是否有可能在第1列中保存值,例如1.0 Each(EA)后跟0.0 / 0.001(EA)...

         df_1
        Out[46]: 
                                              0                      1
        0                       Unit of Measure              Each (EA)
        1                            Conversion               1.0 Each
        2                Net/Gross Weight (lbs)            0.0 / 0.001
        3                     Volume (cubic ft)                    0.0
        4  Shipping Dimensions (inch) L x W x H  0.589 x 0.589 x 0.589
        5                                  GTIN                    NaN

Use: 采用:

df['1'].apply(lambda x:  str(x) + '(EA)' if '(EA)' not in str(x) else x)

if the name of column not is a str then use: 如果列的名称不是str则使用:

df[1].apply(lambda x:  str(x) + '(EA)' if '(EA)' not in str(x) else x)

Try this 尝试这个

df['1']=df['1']+ '(EA)'

It will add (EA) to every row except for the row that has NaN 它将为每行添加(EA),但具有NaN行除外

df_1['1'] = df_1['1'] + " (EA)"

暂无
暂无

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

相关问题 在 dataframe 中添加行,其值与特定列中的值相同 - Add row in dataframe with same value as in specific column 如何向 pandas dataframe 添加一列,该列在一个范围内具有最高值但将其应用于每一行? - How do I add a column to a pandas dataframe which has the highest value in a range but applying it to every row? 如何获取数据框每一行中特定值的列名 - How to get the column name for a specific values in every row of a dataframe 是否有 pandas 方法通过特定列值为每一行添加 dataframe - Is there a pandas way to add a dataframe for each row by a specific column value 如何在Python中仅提取url的特定部分并将其值添加为df中每一行的另一列? - How to extract only a specific part of url in Python and add its value as another column in df for every row? 如何将字符串添加到pandas dataframe列系列中的每个偶数行? - How to add a string to every even row in a pandas dataframe column series? 有没有办法向pandas数据框添加新列,将新列的每个唯一值附加到数据帧的每个现有行? - Is there a way to add a new column to a pandas dataframe, appending each unique value of the new column to every existing row of the dataframe? 如何找到 dataframe 中包含特定列中特定值的最后一行? - How to find the last row in a dataframe that contains a specific value in a specific column? 数据框如何在给定列中找到字符串时添加特定行 - dataframe how to add a specific row when a string is found in a given column 如何添加基于每一行的不同值的列,以从另一个数据框中进行excel类型“ INDEX,MATCH,MATCH”搜索? - How to add a column that based on the different value for every row conducts excel type “INDEX, MATCH, MATCH” search from another dataframe?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM