简体   繁体   中英

Size of networkx.Graph() object?

I have pandas dataframe with 2 columns: col1 , col2 . sys.getsizeof(dataframe) shows 495137153 bytes.

Then i grow a graph:

G = networkx.Graph()
G.add_edges_from(zip(data['col1'], data['col2']))

And now i want to check size of my graph, but sys.getsizeof(G) show 64 bytes

How to get real size of object G?

Update: I checked size of G.edges + size G.nodes , it's about 0.2 GB. But growing graph adds ~5 GB to my used RAM. Why so?

You can estimate the size by adding the size of edge list and node list as shown below. The answer is here

sys.getsizeof(G.edge) + sys.getsizeof(G.node)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM