I recently ran into this issue as well. I think that a weighted average would be more appropriate. So, as a slight modification to your code, after the second "else" (i.e. after checking for isolated nodes) I would add:
# calculate the path of each of the subgraphs (or connected component) and store them in path_temp
path_temp = []
for g in nx.connected_component_subgraphs(G):
path_temp.append(nx.average_shortest_path_length(g,weight = 'weight'))
# create a variable weight that holds the size of each subgraph (or connected component)
# alternatively I have weighted by graph size but we could use anything to weight the average
weights = []
for components in range(numpy.size(nx.connected_components(G))):
weights.append(numpy.size(nx.connected_components(G)[components]))
# compute the weighted average
average = numpy.average(path_temp,weights = weights)
It only came up as a thought because I had an issue where one component was large and the other contained 2 nodes. Thus, the average was very biased to a very small component.