I have data like this
here is data_small.dat
1290 1 7
1300 1 9
1310 9 9
1320 2 7
1330 3 11
1340 11 8
1350 11 9
1360 2 10
1370 12 13
1380 11 12
1390 8 8
1400 0 6
1410 6 11
I have written some code ...
#!/usr/bin/env python
fileInput = open('data_small.dat','r')
fileOutput = open('data_frequency.dat', 'w')
fileList = fileInput.readlines()
for fileLine in fileList:
print ('>>', fileLine)
colList=[i[1] for i in fileList]
colSet=set(colList)
countList=[colList.count(i) for i in colSet]
for item in countList:
fileOutput.write("%s\n" % item)
fileInput.close() fileOutput.close()
But its not writing in correct format. The sought output should be as this
data_frequency.dat
1 2
2 2
3 1
......
......
11 3
.....
where for example 1 means the number and 3 means its frequency of occurence in the first 'data_small.dat' and so on. My target is to read the data in the second column of 'data_small.dat', then count the number of times some number appears and then write in the output 'data_frequency.dat' so that i know how many times the number occurs. this i would like to plot anyways with plotting software like gnuplot. Any idea .... thanks
here is data_small.dat
1290 1 7
1300 1 9
1310 9 9
1320 2 7
1330 3 11
1340 11 8
1350 11 9
1360 2 10
1370 12 13
1380 11 12
1390 8 8
1400 0 6
1410 6 11
I have written some code ...
#!/usr/bin/env python
fileInput = open('data_small.dat','r')
fileOutput = open('data_frequency.dat', 'w')
fileList = fileInput.readlines()
for fileLine in fileList:
print ('>>', fileLine)
colList=[i[1] for i in fileList]
colSet=set(colList)
countList=[colList.count(i) for i in colSet]
for item in countList:
fileOutput.write("%s\n" % item)
fileInput.close() fileOutput.close()
But its not writing in correct format. The sought output should be as this
data_frequency.dat
1 2
2 2
3 1
......
......
11 3
.....
where for example 1 means the number and 3 means its frequency of occurence in the first 'data_small.dat' and so on. My target is to read the data in the second column of 'data_small.dat', then count the number of times some number appears and then write in the output 'data_frequency.dat' so that i know how many times the number occurs. this i would like to plot anyways with plotting software like gnuplot. Any idea .... thanks