string (file1.txt) search from file2.txt
Question: `file1.txt` contains usernames, i.e.

    
    
    tony  
    peter  
    john  
    ...
    

`file2.txt` contains user details, just one line for each user details, i.e.

    
    
    alice 20160102 1101 abc  
    john 20120212 1110 zjc9  
    mary 20140405 0100 few3  
    peter 20140405 0001 io90  
    tango 19090114 0011 n4-8  
    tony 20150405 1001 ewdf  
    zoe 20000211 0111 jn09  
    ...
    

I want to get a shortlist of user details from `file2.txt` by `file1.txt` user
provided, i.e.

    
    
    john 20120212 1110 zjc9  
    peter 20140405 0001 io90  
    tony 20150405 1001 ewdf  
    

How to use python to do this?


Answer: 
    import pandas as pd
    
    df1 = pd.read_csv('df1.txt', header=None)
    df2 = pd.read_csv('df2.txt', header=None)
    df1[0] = df1[0].str.strip() # remove the 2 whitespace followed by the feild
    df2 = df2[0].str[0:-2].str.split(' ').apply(pd.Series) # split the word and remove whitespace
    df = df1.merge(df2)
    
    Out[26]: 
           0         1     2     3
    0   tony  20150405  1001  ewdf
    1  peter  20140405  0001  io90
    2   john  20120212  1110  zjc9
    

