Splitting Regex response column on python
Question: I am receiving an object array after applying `re.findall` for link and
hashtags on Tweets data. My data looks like

    
    
    b=['https://t.co/1u0dkzq2dV', 'https://t.co/3XIZ0SN05Q']
      ['https://t.co/CJZWjaBfJU']
      ['https://t.co/4GMhoXhBQO', 'https://t.co/0V']
      ['https://t.co/Erutsftlnq']
      ['https://t.co/86VvLJEzvG', 'https://t.co/zCYv5WcFDS']
    

Now I want to split it in columns, I am using following

    
    
    df = pd.DataFrame(b.str.split(',',1).tolist(),columns = ['flips','row'])
    

But it is not working because of weird datatype I guess, I tried few other
solutions as well. Nothing worked.And this is what I am expecting, two
separate columns

    
    
    https://t.co/1u0dkzq2dV  https://t.co/3XIZ0SN05Q
    https://t.co/CJZWjaBfJU
    https://t.co/4GMhoXhBQO  https://t.co/0V
    https://t.co/Erutsftlnq
    https://t.co/86VvLJEzvG            
    


Answer: It's not clear from your question what exactly is part of your data. (Does it
include the square brackets and single quotes?). In any case, the pandas
[`read_csv`](http://pandas.pydata.org/pandas-
docs/stable/generated/pandas.read_csv.html) function is very versitile and can
handle ragged data:

    
    
    import StringIO
    import pandas as pd
    
    raw_data = """
    ['https://t.co/1u0dkzq2dV', 'https://t.co/3XIZ0SN05Q']
    ['https://t.co/CJZWjaBfJU']
    ['https://t.co/4GMhoXhBQO', 'https://t.co/0V']
    ['https://t.co/Erutsftlnq']
    ['https://t.co/86VvLJEzvG', 'https://t.co/zCYv5WcFDS']
    """
    
    # You'll probably replace the StringIO part with the filename of your data.
    df = pd.read_csv(StringIO.StringIO(raw_data), header=None, names=('flips','row'))
    
    # Get rid of the square brackets and single quotes
    for col in ('flips', 'row'):
      df[col] = df[col].str.strip("[]'")
    
    df
    

Output:

    
    
                         flips                        row
    0  https://t.co/1u0dkzq2dV    https://t.co/3XIZ0SN05Q
    1  https://t.co/CJZWjaBfJU                        NaN
    2  https://t.co/4GMhoXhBQO            https://t.co/0V
    3  https://t.co/Erutsftlnq                        NaN
    4  https://t.co/86VvLJEzvG    https://t.co/zCYv5WcFDS
    

