在数据帧列中查找特定字符并将单元格复制到另一列

问题描述 投票:0回答:1

在数据框列中查找特定字符($)并将单元格复制到另一列 它无法正常工作,我几乎尝试了所有方法都没有找到 $ 字符。 如果任何 $ 字符单元格不复制到 df2['TOTAL CHARGES2x']

对于 df2['TOTAL CHARGES1x'] 中的 i: 如果在 i 中搜索: print('没有找到 $ - 通过', i) 经过 别的: 如果搜索不在 df2['TOTAL CHARGES1x'] 中: df2['TOTAL CHARGES2x'] = df2.apply(lambda df2: df2['TOTAL CHARGES1x'] if searchfor not in df2['TOTAL CHARGES1x'] else df2['TOTAL CHARGES1x'], axis=1) print('YES, $ 找到 - 未通过',i) 别的: 通过

dataframe copy character
1个回答
0
投票
import pandas as pd
df2 = pd.DataFrame({'TOTAL CHARGES1x': ['$100', '200', '$300', '400']})
for i, value in enumerate(df2['TOTAL CHARGES1x']):
    if '$' not in value:
        df2.at[i, 'TOTAL CHARGES2x'] = value
    else:
        print('YES, $ found - not pass', value)

print(df2)
© www.soinside.com 2019 - 2024. All rights reserved.