'Convert MultiLineString Geometry to LineString in Pandas dataframe

I have a dataframe in which geormtry column is MultiLineString. I need to convert it to LineString to use it in networkx. I used the following code from this question to work with shapefile. But I do not want to create a shapefile from my layer and then convert it. I would like to do it directly in my dataframe! But I cannot get it to work.

with fiona.open('hin_centreline.shp') as source:
with fiona.open('line.shp','w', driver='ESRI Shapefile',
            crs=source.crs,schema=source.schema) as ouput:
    for elem in source:
        reconstruct = shape(elem['geometry']) 
        if elem['geometry']['type'] == 'MultiLineString':
            for line in reconstruct: 
                ouput.write({'geometry':mapping(line),'properties':elem['properties']})
        elif elem['geometry']['type'] == 'LineString':
            ouput.write({'geometry':mapping(reconstruct),'properties':elem['properties']})


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source