1
    pysql = lambda q: pdsql.sqldf(q, globals())
    str1 = "select coalesce(ID1, H_ID, [Alternate Source Unique 
    Identifier]) as Master_ID, [Alternate Source Unique Identifier] as Q_ID 
    from crosswalk;"
     with Timer("Load master_ids:"):
    master_id_list = pysql(str1)
    print("Records: {}".format(len(master_id_list)))
    master_id_list.head()

pySQL runs in just 5 seconds !!

I want to write the second script in python because I can't use pysql :(, Any idea ? your best translation of the second script in python please ?

I have done 2 propositions but not really effective in term of time The first one without Pandas (which is the required)

    def coalesce (df, column_names):
    i=iter(column_names)
    column_name=next(i)
    answer=df[colum_name]
    for column_name in i:
    answer = answer.fillna(df[column_name])
    return answer
    coalesce(df, ['first', 'third', 'second'])

Thank you for your advices !

1 Answers1

0

If all you need is to count the number of records (len(master_id_list)) you can just use it directly:

crosswalk['ID'].size

or

crosswalk.shape

if you are looking for unique values, try:

crosswalk['ID'].unique().size

Dimgold
  • 2,748
  • 5
  • 26
  • 49