diff options
author | Jamal <jamalsenouci@gmail.com> | 2014-11-25 06:39:02 +0000 |
---|---|---|
committer | chebee7i <chebee7i@gmail.com> | 2015-01-05 23:23:54 -0600 |
commit | b15f88632216062468e8134583c2134e1f6fb413 (patch) | |
tree | 54264c7960e0b2c231e9f1b9760eed37c96bbb43 /networkx/convert.py | |
parent | 9b9284ccefc7ad0bc19e55c0de0fdaa9029d6d69 (diff) | |
download | networkx-b15f88632216062468e8134583c2134e1f6fb413.tar.gz |
added Pandas Dataframe into to_networkx_graph
Diffstat (limited to 'networkx/convert.py')
-rw-r--r-- | networkx/convert.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/networkx/convert.py b/networkx/convert.py index 69c9a14c..3d3aa2fa 100644 --- a/networkx/convert.py +++ b/networkx/convert.py @@ -125,6 +125,19 @@ def to_networkx_graph(data,create_using=None,multigraph_input=False): except: raise nx.NetworkXError("Input is not a valid edge list") + # Pandas DataFrame + try: + import pandas as pd + if isinstance(data,pd.DataFrame): + try: + return nx.from_pandas_dataframe(data,create_using=create_using) + except: + raise nx.NetworkXError(\ + "Input is not a correct Pandas DataFrame.") + except ImportError: + warnings.warn('pandas not found, skipping conversion test.', + ImportWarning) + # numpy matrix or ndarray try: import numpy |