'Error: " 'float' object is not subscriptable" whenever I try to print certain values from a list of averafes
I created two variables that give the amount of words in a given context that are both positive and negative respectively within a couple of years. The following code is just that:
NEGSCORE=len(file1)/len(TITLE)*100
POSSCORE=len(file2)/len(TITLE)*100
print(NEGSCORE)
print(POSSCORE)
When I try to test the following code to print out a few values within the span of 30 years randomly I am given this error.
print(NEGSCORE[0:5], '\n', NEGSCORE[-5:])
print(POSSCORE[25],'\n', POSSCORE[-25])
TypeError Traceback (most recent call last)
Input In [240], in <cell line: 2>()
1 # print out a few values
----> 2 print(NEGSCORE[0:5], '\n', NEGSCORE[-5:])
3 print(POSSCORE[25],'\n', POSSCORE[-25])
TypeError: 'float' object is not subscriptable
EDIT:
TITLE = ['19900207.txt','19900327.txt', '19900515.txt', '19900703.txt', '19900821.txt', '19901002.txt', '19901113.txt', '19901218.txt', '19910206.txt', '19910326.txt', '19910514.txt', '19910703.txt', '19910820.txt', '19911001.txt', '19911105.txt', '19911217.txt', '19920205.txt', '19920331.txt', '19920519.txt', '19920701.txt', '19920818.txt', '19921006.txt', '19921117.txt', '19921222.txt', '19930203.txt', '19930323.txt', '19930518.txt', '19930707.txt', '19930817.txt', '19930921.txt', '19931116.txt', '19931221.txt', '19940204.txt', '19940322.txt', '19940517.txt', '19940706.txt', '19940816.txt', '19940927.txt', '19941115.txt', '19941220.txt', '19950201.txt', '19950328.txt', '19950523.txt', '19950706.txt', '19950822.txt', '19950926.txt', '19951115.txt', '19951219.txt', '19960130.txt', '19960326.txt', '19960521.txt', '19960702.txt', '19960820.txt', '19960924.txt', '19961113.txt', '19961217.txt', '19970204.txt', '19970325.txt', '19970520.txt', '19970701.txt', '19970819.txt', '19970930.txt', '19971112.txt', '19971216.txt', '19980203.txt', '19980331.txt', '19980519.txt', '19980630.txt', '19980818.txt', '19980929.txt', '19981117.txt', '19981222.txt', '19990202.txt', '19990330.txt', '19990518.txt', '19990629.txt', '19990824.txt', '19991005.txt', '19991116.txt', '19991221.txt', '20000202.txt', '20000321.txt', '20000516.txt', '20000628.txt', '20000822.txt', '20001003.txt', '20001115.txt', '20001219.txt', '20010131.txt', '20010320.txt', '20010515.txt', '20010627.txt', '20010821.txt', '20011002.txt', '20011106.txt', '20011211.txt', '20020130.txt', '20020319.txt', '20020507.txt', '20020626.txt', '20020813.txt', '20020924.txt', '20021106.txt', '20021210.txt', '20030129.txt', '20030318.txt', '20030506.txt', '20030625.txt', '20030812.txt', '20030916.txt', '20031028.txt', '20031209.txt', '20040128.txt', '20040316.txt', '20040504.txt', '20040630.txt', '20040810.txt', '20040921.txt', '20041110.txt', '20041214.txt', '20050202.txt', '20050322.txt', '20050503.txt', '20050630.txt', '20050809.txt', '20050920.txt', '20051101.txt', '20051213.txt', '20060131.txt', '20060328.txt', '20060510.txt', '20060629.txt', '20060808.txt', '20060920.txt', '20061025.txt', '20061212.txt', '20070131.txt', '20070321.txt', '20070509.txt', '20070628.txt', '20070807.txt', '20070918.txt', '20071031.txt', '20071211.txt', '20080130.txt', '20080318.txt', '20080430.txt', '20080625.txt', '20080805.txt', '20080916.txt', '20081029.txt', '20081216.txt', '20090128.txt', '20090318.txt', '20090429.txt', '20090624.txt', '20090812.txt', '20090923.txt', '20091104.txt', '20091216.txt', '20100127.txt', '20100316.txt', '20100428.txt', '20100623.txt', '20100810.txt', '20100921.txt', '20101103.txt', '20101214.txt', '20110126.txt', '20110315.txt', '20110427.txt', '20110622.txt', '20110809.txt', '20110921.txt', '20111102.txt', '20111213.txt', '20120125.txt', '20120313.txt', '20120425.txt', '20120620.txt', '20120801.txt', '20120913.txt', '20121024.txt', '20121212.txt', '20130130.txt', '20130320.txt', '20130501.txt', '20130619.txt', '20130731.txt', '20130918.txt', '20131030.txt', '20131218.txt', '20140129.txt', '20140319.txt', '20140430.txt', '20140618.txt', '20140730.txt', '20140917.txt', '20141029.txt', '20141217.txt', '20150128.txt', '20150318.txt', '20150429.txt', '20150617.txt', '20150729.txt', '20150917.txt', '20151028.txt', '20151216.txt', '20160127.txt', '20160316.txt', '20160427.txt', '20160615.txt', '20160727.txt', '20160921.txt', '20161102.txt', '20161214.txt', '20170201.txt', '20170315.txt', '20170503.txt', '20170614.txt', '20170726.txt', '20170920.txt', '20171101.txt', '20171213.txt', '20180131.txt', '20180321.txt', '20180502.txt', '20180613.txt', '20180801.txt', '20180926.txt', '20181108.txt', '20181219.txt', '20190130.txt', '20190320.txt', '20190501.txt', '20190619.txt', '20190731.txt', '20190918.txt', '20191030.txt', '20191211.txt', '20200129.txt', '20200315.txt', '20200429.txt', '20200610.txt', '20200729.txt', '20200916.txt', '20201105.txt', '20201216.txt', '20210127.txt', '20210317.txt', '20210428.txt', '20210616.txt', '20210728.txt', '20210922.txt', '20211103.txt', '20211215.txt']
print(TITLE[0]) # FIRST FILE NAME
print(TITLE[-1]) # LAST FILE NAME
print(type(TITLE),type(TITLE[0]))
19900207.txt
20211215.txt
<class 'list'> <class 'str'>
Essentially I am obtaining a dataset that contains 256 negative scores (call this variable "NEGSCORE") and a dataset of 256 positive scores (call this variable "POSSCORE"). The first element of NEGSCORE for example, corresponds to the negative score calculated using the 19900207 FOMC minutes, and the last element corresponds to the negative score calculated using the 20211215 FOMC minutes. The Formula used is (count of negative words)/(count of total words) *100. The total words is each individual text file in TITLE and negative words is in a separate text file that has a len of 19.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|