1

I'm using the following for loop that runs over a directory that contains a few files with a list of numbers (nodes).

for filename in os.listdir(nodes_path):
    nodes_arr = np.genfromtxt(os.path.join(nodes_path, filename), delimiter=',')
    print (nodes_arr)
    print (len(nodes_arr))

In this example I have 4 files in the directory. I've set the path to it in nodes_path. The problem is I'm getting a 5th string that contains nan. output:

[22718045.  1172884.  1434416. ... 84287109. 84328117. 84381796.]
219463
[6.9590000e+03 7.7180000e+03 1.3373000e+04 ... 8.3828038e+07 8.4007117e+07
 8.4046414e+07]
63309
[56467551. 12073526. 12655638. ... 84299018. 84312857. 84388811.]
271456
[81614683. 11760788. 15679375. ... 84431649. 84448307. 84458895.]
274465
[nan nan nan nan]
4

I don't understand why this happens.

petezurich
  • 9,280
  • 9
  • 43
  • 57
  • when adding `dtype=None`, i got the metadata of the folder: `[b'[.ShellClassInfo]' b'InfoTip=This folder is shared online.' b'IconFile=C:\\...\\googledrivesync.exe' b'IconIndex=16']` this is what creates the `nan` array. but how do I get rid of it? – user2999931 Jan 06 '20 at 11:34

1 Answers1

0

Solution found: Excluding the last file from the for loop as follows:

for filename in os.listdir(nodes_path)[:-1]:
DO ...