Pandas, DataFrames, R. , DataFrame df, . ( pandas.read_table. . Thid: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.io.parsers.read_table.html).
groupby id.
gps = df.groupby("id")
print gps.groups
Out: {5: [0, 1], 6: [2, 3], 7: [4, 5, 6], 8: [7], 9: [8], 10: [9]}
groups , .
featureCode.
unqFet = list(set(df["featureCode"]))
final = pandas.DataFrame(columns=unqFet, index=unqFet)
final = final.fillna(0)
print final
Out:
PCLI PPLC PPL
PCLI 0 0 0
PPLC 0 0 0
PPL 0 0 0
, final.
for g in gps.groups.values():
for i in range(len(g)):
for j in range(len(g)):
if i != j:
final[ df["featureCode"][g[i]] ][ df["featureCode"][g[j]] ] += 1
print final
Out:
PCLI PPLC PPL
PCLI 0 3 1
PPLC 3 0 1
PPL 1 1 0