我有 pandas 数据框,由 10 列组成。
所以每一步都可能发生各种排列,我想从所有数据集中绘制一个有向图。
目前networkx仅支持2列
# libraries
import pandas as pd
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
# Build your graph
G=nx.from_pandas_dataframe(df, 'src', 'dest',create_using=nx.DiGraph())
# Plot it
nx.draw(G, with_labels=True)
plt.show()
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我如何为两列以上的有向图绘制它吗
我正在尝试替换数据框中的某些数据以包含额外的“F”。
代码应如下所示:
if testdata['pfType'] =='NK225M'|testdata['pfType'] == 'TOPIXM':
testdata['pfType'] = ' testdata['pfType'] & 'F';
Run Code Online (Sandbox Code Playgroud)
我试图这样做:
testdata['pfType'][testdata['pfType'] == 'NK225M'] = 'NK225MF'
testdata['pfType'][testdata['pfType'] == 'TOPIXM'] = 'TOPIXMF'
Run Code Online (Sandbox Code Playgroud)
但它并没有改变这些值,如果它是 NK225M 或 TOPIXM,那么将“F”添加到字符串的最佳方法是什么。
我正在尝试.format()在想要打印的 python 中使用
1 到 N 以空格填充,以便所有字段都采用与二进制值相同的宽度。
以下是我迄今为止尝试过的
n=int(input())
width = len("{0:b}".format(n))
for num in range(1,n+1):
print (' '.join(map(str,(num,oct(num).replace('0o',''),hex(num).replace('0x',''),bin(num).replace('0b','')))))
Run Code Online (Sandbox Code Playgroud)
我不知道如何在.format()这里正确使用该功能。请帮忙
我有一个看起来像熊猫的“数据框”,如果需要pd.Dataframe下表,也请告诉我。
iD a b c
c1 2 3 4
c1 2 3 4
c1 2 3 4
c1 2 E 4
c1 2 3 4
c2 3 4 5
c2 3 4 5
c2 3 E 5
c2 3 4 5
Run Code Online (Sandbox Code Playgroud)
现在在此数据帧中有两个ID c1和c2。每当“ E”出现在“ b”列中时,我想删除上面的所有行。
我的最终数据框应该看起来像
iD a b c
c1 2 E 4
c1 2 3 4
c2 3 E 5
c2 3 4 5
Run Code Online (Sandbox Code Playgroud)
只是想使问题简短,以便人们回答。请让我知道是否需要在数据框中添加一些额外的数据点