def apply_ht_scores(dataframe):
# Load the ht score dataframe
ht_scores = pandas.read_csv('{0}ht_scores.csv'.format(config['result_data']), index_col=0)
dataframe['phone'] = dataframe['phone'].map(lambda x: re.sub('[^0-9]', '', str(x)))
# Make the column a numeric column for merging
#dataframe['phone'] = pandas.to_numeric(dataframe['phone'])
final = dataframe.merge(ht_scores, how='left', left_on='phone', right_index=True)
# Drop the content column and drop the index column
final.drop('content', axis=1, inplace=True)
if os.path.isfile('{0}ad_chars_final.csv'.format(config['result_data'])):
lock.acquire()
print 'lock has been set for file {0}'.format(file)
final.to_csv('{0}ad_chars_final.csv'.format(config['result_data']), mode='a', header=False, encoding='utf-8', index=False)
lock.release()
else:
final.to_csv('{0}ad_chars_final.csv'.format(config['result_data']), header=True, encoding='utf-8', index=False)
create_location_files.py 文件源码
python
阅读 27
收藏 0
点赞 0
评论 0
评论列表
文章目录