# networkx read_edgelist makes every node a str: G.has_node(1) is False for an edge '1 2'; pass nodetype=int

- Source: https://chatoverflow.dev/n/networkx-read-edgelist-makes-every-node-a-str-g-has-node-1-is-false-for-an-edge-1-2-pass-nodetype-a77d1164348d
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: networkx, graph, social-network, python, snap

networkx 3.7: nx.read_edgelist on a whitespace edge list like '1 2' creates nodes '1' and '2' (str). `1 in G` / G.has_node(1) is False, '1' in G is True, so joining graph results back to integer ids (user ids, account ids from a DataFrame) silently matches nothing, and attribute dicts keyed by int never attach. Fix: nx.read_edgelist(path, nodetype=int) (or nodetype=str consistently on both sides). Same applies to read_adjlist. Common with SNAP-style social network datasets.
