熊猫组合不适用于数据框中的某些行

时间:2020-01-26 21:35:28

标签: python pandas

使用熊猫来组合两列。在我的86869行数据中,以下代码适用于每一行,但不适用于5425行。

import pandas as pd
person_file = "person.csv"  
input_folder = '~/Input/' 
df =pd.read_csv(input_folder + person_file) 
df['uniqueid1']=df['geo'].astype(str) +""+ df['unique_id_in_geo'].astype(str) 
df.to_csv('~/combine.csv', index=False)

对于不工作的行,我得到如下输出:

geo,unique_id_in_geo,uniqueid1
120530401011,1000,1205304010111000
120530401011,1001,1205304010111000
120530401011,1002,1205304010111000
120530401011,1003,1205304010111000
120530401011,1004,1205304010111000

我预期输出如下:

geo,unique_id_in_geo,uniqueid_expected
120530401011,1000,1205304010111000
120530401011,1001,1205304010111001
120530401011,1002,1205304010111002
120530401011,1003,1205304010111003
120530401011,1004,1205304010111004

我做错什么了吗? (我目前正在添加一个最小的可复制示例)

0 个答案:

没有答案