AttributeError: module 'networkx' n'a pas d'attribut "from_pandas_dataframe'
J'ai networkx v. 2.1
. pour le faire fonctionner w/pandas dataframe, j'ai essayé de suivre:
- installé via
pip3
, cela n'a pas généré d'Atrribute Error
comme dans le titre, donc désinstallé. - ré-installé avec"
python3 setup.py install
"
Description de l'erreur.
AttributeError: module 'networkx' n'a pas d'attribut " from_pandas_dataframe`
Étapes pour reproduire l'Erreur:
J'ai importé des données à l'aide csv
. Je l'ai fait parce que je voulais juste lire seulement 5000 lignes du jeu de données.
x=pd.DataFrame([x for x in rawData[:5000]])
x[:10]
0 1 2
0 228055 231908 1
1 228056 228899 1
2 228050 230029 1
3 228059 230564 1
4 228059 230548 1
5 70175 70227 1
6 89370 236886 1
7 89371 247658 1
8 89371 249558 1
9 89371 175997 1
g_data=G=nx.from_pandas_dataframe(x)
module 'networkx' has no attribute 'from_pandas_dataframe'
Je sais que je suis absent de la from_pandas_dataframe
, mais ne peux pas trouver un moyen de l'installer.
[m for m in nx.__dir__() if 'pandas' in m]
['from_pandas_adjacency',
'to_pandas_adjacency',
'from_pandas_edgelist',
'to_pandas_edgelist']
Vous devez vous connecter pour publier un commentaire.
Dans networkx 2.0
from_pandas_dataframe
a été supprimé. (https://networkx.github.io/documentation/stable/release/release_2.0.html)Au lieu de cela, vous pouvez utiliser
from_pandas_edgelist
https://networkx.github.io/documentation/stable/reference/generated/networkx.convert_matrix.from_pandas_edgelist.html?highlight=from_pandas_edgelist#networkx.convert_matrix.from_pandas_edgelist
Ensuite, vous devrez:
g_data=G=nx.from_pandas_edgelist(x, 1, 2, edge_attr=True)
pip install networkx
mais seulement obtenu 1.11 qui n'ont pasfrom_pandas_edgelist
, puis j'ai essayépip install --upgrade networkx
, a finalement obtenufrom_pandas_edgelist
Un simple graphique:
Ce solution permet ainsi: