Convert a list of lists of tuples to pandas dataframe

后端 未结 1 1160
离开以前
离开以前 2021-01-23 06:16

I\'m trying to transform a list of lists of tuples to a pandas dataframe but can\'t figure out how to do so. My addresses are structured like so:

addresses = [
         


        
1条回答
  •  遥遥无期
    2021-01-23 06:56

    You can convert each record to a dictionary and then use DataFrame.from_records:

    pd.DataFrame.from_records([{k: v for v, k in row} for row in addresses])
    
    #      city house   house_number    road
    #0  arlesey beds              68    church lane
    #1  arlesey beds              85    church lane
    #2  arlesey beds              85    high street
    #3  arlesey beds             NaN    high street
    #4  arlesey beds             NaN    high street
    

    0 讨论(0)
提交回复
热议问题