1

I would need to read data from a pajek file consisting of partitions (files .clu). Looking for more information on how reading a pajek format, I've found the following question: Reading a Pajek Dataset into Networkx

The answer refers to partitions of the vertex set. I've tried to open a file as follows example = nx.read_pajek('path/file.paj') or, alternatively,

with open('path/file.paj') as txtfile:
    comments = []
    data = []
    part = []
    for line in txtfile:
        if line.startswith('*'):
            comment = line
            comments.append(comment)
            if part:
                data.append(part)
                part = []
        else:
            if comment.startswith('*Vertices') and len(line.split()) > 1:
                sublist = line.split('"')
                sublist = sublist[:2] + sublist[-1].split()
                part.append(sublist)
            elif not line.isspace():
                part.append(line.split())
    data.append(part)

but the file cannot be read correctly as it returns [[]].

I guess that the above method cannot be applied in case of partitions.

Can I ask you how to access a .paj having partitions in it? Happy to provide an example of dataset (you might found some example on the link provided above).

Examples of files with partitions might be that one mentioned on the question at the above link (e.g. http://vlado.fmf.uni-lj.si/pub/networks/data/esna/SanJuanSur.htm) or other files in the repository http://vlado.fmf.uni-lj.si/pub/networks/data (e.g. http://vlado.fmf.uni-lj.si/pub/networks/data/2mode/Sandi/Sandi.htm or http://vlado.fmf.uni-lj.si/pub/networks/data/2mode/DutchElite.htm)

LdM
  • 674
  • 7
  • 23
  • Can you share an example file with us? – joanis Nov 08 '22 at 23:48
  • Hi joanis, added in the question. Thanks – LdM Nov 09 '22 at 00:37
  • 1
    Modifying the pajek file the way Aric suggested in [this](https://stackoverflow.com/questions/23207136/reading-a-pajek-dataset-into-networkx/23208024#23208024) SO post worked for me. And then loading it with `G = nx.read_pajek('SanJuanSur2.paj')` – jylls Nov 09 '22 at 19:38
  • Hi jylls, thanks. Does it work also for the other file, DE, in the link I mentioned in my post? Because I am reading it as suggested in Aric’s answer, removing that part, but it is still returning empty nets – LdM Nov 09 '22 at 20:02

1 Answers1

0

Executing your code, I could read the downloaded SanJuanSur2.paj very well.

What make you think that you have a partition problem?

  • Hi Melchiorlm. I cannot read the other file (DutchElite). Are you able to open it and visualise all the datasets? Doing the same as per SanJuanSur2 dataset does not allow me to read it – LdM Nov 17 '22 at 20:50
  • 1
    @melchiorlm3Tal, could you please move the answer to a comment? It looks like that and does not answer my question (other users did the same, testing the dataset SanJuanSur) :) thanks – LdM Nov 17 '22 at 22:14
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 19 '22 at 16:11
  • Trying DutchElite I got an error, too. ## change the open statement open(file: _OpenFile, ..., **encoding: str | None = ..., errors: str | None = ...**, ...) ```python pajFiles = ['/home/.../Downloads/SanJuanSur2.paj', '/home/.../Downloads/DutchElite/DutchElite.paj'] for file in pajFiles: # with open(file) as txtfile: with open(file, encoding='cp437') as txtfile: print(f'file: {file}') ... print(f'first 100 chars: { str(data)[:100]}') ``` file: .../DutchElite/DutchElite.paj first line: % Data ... – MelchiorIm3Tal Nov 28 '22 at 11:47
  • Sorry, I am not allowed to comment to the original question. – MelchiorIm3Tal Nov 28 '22 at 11:48