Pandas 属性错误:模块';networkx';没有属性';来自"熊猫"数据帧';
我有Pandas 属性错误:模块';networkx';没有属性';来自"熊猫"数据帧';,pandas,networkx,Pandas,Networkx,我有networkxv。2.1。为了使其与熊猫数据帧一起工作,我尝试了以下方法: 通过pip3安装,但与标题中的a属性错误不起作用,因此已卸载 使用“python3 setup.py安装程序”重新安装 错误描述 AttributeError:模块“networkx”没有来自\u\u数据帧的属性` 重现错误的步骤: 我使用csv导入数据。之所以这样做,是因为我只想从数据集中读取5000行 x=pd.DataFrame([x for x in rawData[:5000]]) x[:10]
networkxv。2.1
。为了使其与熊猫数据帧一起工作,我尝试了以下方法:
- 通过
安装,但与标题中的pip3
不起作用,因此已卸载李>a属性错误
- 使用“
python3 setup.py安装程序”重新安装
csv
导入数据。之所以这样做,是因为我只想从数据集中读取5000行
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'
我知道我缺少数据框中的,但找不到安装方法
[m for m in nx.__dir__() if 'pandas' in m]
['from_pandas_adjacency',
'to_pandas_adjacency',
'from_pandas_edgelist',
'to_pandas_edgelist']
这也有助于:
G = nx.DiGraph()
G.add_weighted_edges_from([tuple(x) for x in x.values])
nx.info(G)
'Name: \nType: DiGraph\nNumber of nodes: 5713\nNumber of edges: 5000\nAverage in degree: 0.8752\nAverage out degree: 0.8752'
在networkx 2.0中,从\u pandas\u数据帧
相反,您可以使用
然后您将有:
g_data=G=nx.from_pandas_edgelist(x, 1, 2, edge_attr=True)
一个简单的图表:
import pandas as pd
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
# Build a dataframe with 4 connections
df = pd.DataFrame({'from': \['A', 'B', 'C', 'A'\], 'to': \['D', 'A', 'E', 'C'\]})
# Build your graph
G = nx.from_pandas_edgelist(df, 'from', 'to')
# Plot it
nx.draw(G, with_labels=True)
plt.show()
我使用的是pip安装networkx
,但从pandas\u edgelist
中只得到了1.11,它没有,然后我尝试了pip安装——升级networkx
,最后从pandas\u edgelist中得到了,无向图呢?这与答案无关