如何根据数据集中给定的权重(销售或成本)设置边缘宽度...。如何解决?
import networkx as nx
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
df=pd.read_csv("C:/Users/RahulVicky/Documents/new/flight_load.csv")
df_rotation=pd.read_csv("C:/Users/RahulVicky/Documents/new/Rotation.csv")
df=df.rename({"Sales INR":"Sales","Load Factor":"LF"},axis=1)
df['Origin']=df_rotation['Origin'].astype('str')
df['Destination']=df_rotation['Destn'].astype('str')
df['Sector']=df['Sector'].astype('str')
help(type)
DG=nx.Graph()
DG.add_nodes_from(df['Origin'])
DG.node()
subset = df_rotation[['Origin', 'Destn']]
tuples = [tuple(x) for x in subset.values]
tuples
DG.add_edges_from(tuples,color='r',weight=df["Sales"])
nx.draw(DG,with_labels=True)
尝试时出现此错误:
ValueError: setting an array element with a sequence.
我希望按照给定的重量(即销售量)获得边缘厚度,尽管我尝试使用销售标准化价值,但仍然遇到相同的错误。