Help us understand the problem. What is going on with this article?

Pythonでクラスター係数を算出

Pythonのnetworkxというパッケージを用いて,クラスター係数を出していきます.

もとのデータは,2015.csv から 2018.csv という名前であり,Nodeは「引用者」「被引用者」とします.

事前に,pandas と networkx を install しておきましょう.

cluster.py
import pandas as pd
import networkx as nx

def CENTRALITY(y):
  #pandas の read_csv('',dtype={})
  data=pd.read_csv(f'{y}.csv',dtype={'引用者ID':'str','被引用者ID':'str'})

  print(f'readed file {y}')

  #dataのサイズを確認
  print(len(data))

  #networkx を用いて,dataをグラフとして割り当て(data,edge名,edge名)
  G=nx.from_pandas_edgelist(data2,'引用者ID','被引用者ID')
  print(f'generated graph {y}')

  #クラスター係数と次数の計算 pandas.DataFrame  dict = dictionaly型
  out=pd.DataFrame(dict(
    CLUSTER=nx.clustering(G),
    degree=dict(nx.degree(G))
  ))
  print(f'calculated centralities {y}')

  #ファイルへ出力 pd.DataFrame.to_csv('',)
  out.index.name='ID'
  out.to_csv(f'out/cluster_{y}_v2.csv',float_format='%.10f')
  print(f'generated file {y}')

  pbar.update(1)

def main():

       for i in range(2015, 2018):
                CENTRALITY(i)

if __name__ == "__main__":
  main()

うまくいきましたら,「いいね」お願いしまーす.

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away