How to transform the data and calculate the TFIDF value?
up vote
0
down vote
favorite
My data format is:
datas = {[1,2,4,6,7],[2,3],[5,6,8,3,5],[2],[93,23,4,5,11,3,5,2],...}
Each element in datas is a sentence ,and each number is a word.I want to get the TFIDF value for each number. How to do it with sklearn or other ways?
My code:
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.feature_extraction.text import CountVectorizer
datas = {[1,2,4,6,7],[2,3],[5,6,8,3,5],[2],[93,23,4,5,11,3,5,2]}
vectorizer=CountVectorizer()
transformer = TfidfTransformer()
tfidf = transformer.fit_transform(vectorizer.fit_transform(datas))
print(tfidf)
My code doesn't work.Error:
Traceback (most recent call last): File
"C:/Users/zhuowei/Desktop/OpenNE-master/OpenNE-
master/src/openne/buildTree.py", line 103, in <module>
X = vectorizer.fit_transform(datas) File
"C:UserszhuoweiAnaconda3libsite-
packagessklearnfeature_extractiontext.py", line 869, in fit_transform
self.fixed_vocabulary_) File "C:UserszhuoweiAnaconda3libsite-
packagessklearnfeature_extractiontext.py", line 792, in _count_vocab
for feature in analyze(doc): File
"C:UserszhuoweiAnaconda3libsite-
packagessklearnfeature_extractiontext.py", line 266, in <lambda>
tokenize(preprocess(self.decode(doc))), stop_words) File
"C:UserszhuoweiAnaconda3libsite-
packagessklearnfeature_extractiontext.py", line 232, in <lambda>
return lambda x: strip_accents(x.lower())
AttributeError: 'int' object has no attribute 'lower'
python-3.x scikit-learn nlp tf-idf
|
show 1 more comment
up vote
0
down vote
favorite
My data format is:
datas = {[1,2,4,6,7],[2,3],[5,6,8,3,5],[2],[93,23,4,5,11,3,5,2],...}
Each element in datas is a sentence ,and each number is a word.I want to get the TFIDF value for each number. How to do it with sklearn or other ways?
My code:
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.feature_extraction.text import CountVectorizer
datas = {[1,2,4,6,7],[2,3],[5,6,8,3,5],[2],[93,23,4,5,11,3,5,2]}
vectorizer=CountVectorizer()
transformer = TfidfTransformer()
tfidf = transformer.fit_transform(vectorizer.fit_transform(datas))
print(tfidf)
My code doesn't work.Error:
Traceback (most recent call last): File
"C:/Users/zhuowei/Desktop/OpenNE-master/OpenNE-
master/src/openne/buildTree.py", line 103, in <module>
X = vectorizer.fit_transform(datas) File
"C:UserszhuoweiAnaconda3libsite-
packagessklearnfeature_extractiontext.py", line 869, in fit_transform
self.fixed_vocabulary_) File "C:UserszhuoweiAnaconda3libsite-
packagessklearnfeature_extractiontext.py", line 792, in _count_vocab
for feature in analyze(doc): File
"C:UserszhuoweiAnaconda3libsite-
packagessklearnfeature_extractiontext.py", line 266, in <lambda>
tokenize(preprocess(self.decode(doc))), stop_words) File
"C:UserszhuoweiAnaconda3libsite-
packagessklearnfeature_extractiontext.py", line 232, in <lambda>
return lambda x: strip_accents(x.lower())
AttributeError: 'int' object has no attribute 'lower'
python-3.x scikit-learn nlp tf-idf
What did you search for in order to solve this, and what did you find? What did you try, and why didn't it work?
– tripleee
Nov 19 at 8:33
I have put my code above
– Z Mario
Nov 19 at 8:43
Thanks for the code. Please include the full traceback still, though.
– tripleee
Nov 19 at 8:44
ok I have add the full traceback, I think my way is wrong ,but I don't know how to fix it
– Z Mario
Nov 19 at 8:52
Unfortunately, that doesn't look like a full traceback. Alsostr(nodes[0])
in the traceback doesn't seem to correspond to anything in your question. You should probably review the guidance for how to create a Minimal, Complete, and Verifiable example.
– tripleee
Nov 19 at 8:53
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
My data format is:
datas = {[1,2,4,6,7],[2,3],[5,6,8,3,5],[2],[93,23,4,5,11,3,5,2],...}
Each element in datas is a sentence ,and each number is a word.I want to get the TFIDF value for each number. How to do it with sklearn or other ways?
My code:
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.feature_extraction.text import CountVectorizer
datas = {[1,2,4,6,7],[2,3],[5,6,8,3,5],[2],[93,23,4,5,11,3,5,2]}
vectorizer=CountVectorizer()
transformer = TfidfTransformer()
tfidf = transformer.fit_transform(vectorizer.fit_transform(datas))
print(tfidf)
My code doesn't work.Error:
Traceback (most recent call last): File
"C:/Users/zhuowei/Desktop/OpenNE-master/OpenNE-
master/src/openne/buildTree.py", line 103, in <module>
X = vectorizer.fit_transform(datas) File
"C:UserszhuoweiAnaconda3libsite-
packagessklearnfeature_extractiontext.py", line 869, in fit_transform
self.fixed_vocabulary_) File "C:UserszhuoweiAnaconda3libsite-
packagessklearnfeature_extractiontext.py", line 792, in _count_vocab
for feature in analyze(doc): File
"C:UserszhuoweiAnaconda3libsite-
packagessklearnfeature_extractiontext.py", line 266, in <lambda>
tokenize(preprocess(self.decode(doc))), stop_words) File
"C:UserszhuoweiAnaconda3libsite-
packagessklearnfeature_extractiontext.py", line 232, in <lambda>
return lambda x: strip_accents(x.lower())
AttributeError: 'int' object has no attribute 'lower'
python-3.x scikit-learn nlp tf-idf
My data format is:
datas = {[1,2,4,6,7],[2,3],[5,6,8,3,5],[2],[93,23,4,5,11,3,5,2],...}
Each element in datas is a sentence ,and each number is a word.I want to get the TFIDF value for each number. How to do it with sklearn or other ways?
My code:
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.feature_extraction.text import CountVectorizer
datas = {[1,2,4,6,7],[2,3],[5,6,8,3,5],[2],[93,23,4,5,11,3,5,2]}
vectorizer=CountVectorizer()
transformer = TfidfTransformer()
tfidf = transformer.fit_transform(vectorizer.fit_transform(datas))
print(tfidf)
My code doesn't work.Error:
Traceback (most recent call last): File
"C:/Users/zhuowei/Desktop/OpenNE-master/OpenNE-
master/src/openne/buildTree.py", line 103, in <module>
X = vectorizer.fit_transform(datas) File
"C:UserszhuoweiAnaconda3libsite-
packagessklearnfeature_extractiontext.py", line 869, in fit_transform
self.fixed_vocabulary_) File "C:UserszhuoweiAnaconda3libsite-
packagessklearnfeature_extractiontext.py", line 792, in _count_vocab
for feature in analyze(doc): File
"C:UserszhuoweiAnaconda3libsite-
packagessklearnfeature_extractiontext.py", line 266, in <lambda>
tokenize(preprocess(self.decode(doc))), stop_words) File
"C:UserszhuoweiAnaconda3libsite-
packagessklearnfeature_extractiontext.py", line 232, in <lambda>
return lambda x: strip_accents(x.lower())
AttributeError: 'int' object has no attribute 'lower'
python-3.x scikit-learn nlp tf-idf
python-3.x scikit-learn nlp tf-idf
edited Nov 19 at 9:01
asked Nov 19 at 8:20
Z Mario
246
246
What did you search for in order to solve this, and what did you find? What did you try, and why didn't it work?
– tripleee
Nov 19 at 8:33
I have put my code above
– Z Mario
Nov 19 at 8:43
Thanks for the code. Please include the full traceback still, though.
– tripleee
Nov 19 at 8:44
ok I have add the full traceback, I think my way is wrong ,but I don't know how to fix it
– Z Mario
Nov 19 at 8:52
Unfortunately, that doesn't look like a full traceback. Alsostr(nodes[0])
in the traceback doesn't seem to correspond to anything in your question. You should probably review the guidance for how to create a Minimal, Complete, and Verifiable example.
– tripleee
Nov 19 at 8:53
|
show 1 more comment
What did you search for in order to solve this, and what did you find? What did you try, and why didn't it work?
– tripleee
Nov 19 at 8:33
I have put my code above
– Z Mario
Nov 19 at 8:43
Thanks for the code. Please include the full traceback still, though.
– tripleee
Nov 19 at 8:44
ok I have add the full traceback, I think my way is wrong ,but I don't know how to fix it
– Z Mario
Nov 19 at 8:52
Unfortunately, that doesn't look like a full traceback. Alsostr(nodes[0])
in the traceback doesn't seem to correspond to anything in your question. You should probably review the guidance for how to create a Minimal, Complete, and Verifiable example.
– tripleee
Nov 19 at 8:53
What did you search for in order to solve this, and what did you find? What did you try, and why didn't it work?
– tripleee
Nov 19 at 8:33
What did you search for in order to solve this, and what did you find? What did you try, and why didn't it work?
– tripleee
Nov 19 at 8:33
I have put my code above
– Z Mario
Nov 19 at 8:43
I have put my code above
– Z Mario
Nov 19 at 8:43
Thanks for the code. Please include the full traceback still, though.
– tripleee
Nov 19 at 8:44
Thanks for the code. Please include the full traceback still, though.
– tripleee
Nov 19 at 8:44
ok I have add the full traceback, I think my way is wrong ,but I don't know how to fix it
– Z Mario
Nov 19 at 8:52
ok I have add the full traceback, I think my way is wrong ,but I don't know how to fix it
– Z Mario
Nov 19 at 8:52
Unfortunately, that doesn't look like a full traceback. Also
str(nodes[0])
in the traceback doesn't seem to correspond to anything in your question. You should probably review the guidance for how to create a Minimal, Complete, and Verifiable example.– tripleee
Nov 19 at 8:53
Unfortunately, that doesn't look like a full traceback. Also
str(nodes[0])
in the traceback doesn't seem to correspond to anything in your question. You should probably review the guidance for how to create a Minimal, Complete, and Verifiable example.– tripleee
Nov 19 at 8:53
|
show 1 more comment
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
You are using CountVectorizer
which requires an iterable of strings. Something like:
datas = ['First sentence',
'Second sentence', ...
...
'Yet another sentence']
But your data is a list of lists, which is why the error occurs. You need to make the inner lists as strings for the CountVectorizer to work. You can do this:
datas = [' '.join(map(str, x)) for x in datas]
This will result in datas
like this:
['1 2 4 6 7', '2 3', '5 6 8 3 5', '2', '93 23 4 5 11 3 5 2']
Now this form is consumable by CountVectorizer
. But even then you will not get proper results, because of the default token_pattern
in CountVectorizer:
token_pattern : ’(?u)bww+b’
string Regular expression denoting what constitutes a
“token”, only used if analyzer == 'word'. The default regexp select
tokens of 2 or more alphanumeric characters (punctuation is completely
ignored and always treated as a token separator)
In order for it to consider your numbers as words, you will need to change it so that it can accept single letters as words by doing this:
vectorizer = CountVectorizer(token_pattern=r"(?u)bw+b")
Then it should work. But now your numbers are changed into strings
It worked ,thank you very much
– Z Mario
Nov 19 at 12:31
add a comment |
up vote
-1
down vote
Using our term frequency matrix, the idf weight for can be calculated like below.
# idf
( idf <- log( ncol(tf) / ( 1 + rowSums(tf != 0) ) ) )
Now that we have our matrix with the term frequency and the idf weight, we’re ready to calculate the full tf-idf weight. To do this matrix multiplication, we will also have to transform the idf vector into a diagonal matrix. Both calculations are shown below.
# diagonal matrix
( idf <- diag(idf) )
tf_idf <- crossprod(tf, idf)
colnames(tf_idf) <- rownames(tf)
tf_idf
For each vector v→, you divide it by its norm (length, magnitude). Calculation as below
# Note that normalization is computed "row-wise"
tf_idf / sqrt( rowSums( tf_idf^2 ) )
This doesn't look like Python at all.
– tripleee
Nov 19 at 8:32
but how to build frequency matrix ?
– Z Mario
Nov 19 at 8:47
Case of "R" stackoverflow.com/questions/43357603/… Case of Python stackoverflow.com/questions/41300583/…
– Amal Dominic
Nov 19 at 9:15
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
You are using CountVectorizer
which requires an iterable of strings. Something like:
datas = ['First sentence',
'Second sentence', ...
...
'Yet another sentence']
But your data is a list of lists, which is why the error occurs. You need to make the inner lists as strings for the CountVectorizer to work. You can do this:
datas = [' '.join(map(str, x)) for x in datas]
This will result in datas
like this:
['1 2 4 6 7', '2 3', '5 6 8 3 5', '2', '93 23 4 5 11 3 5 2']
Now this form is consumable by CountVectorizer
. But even then you will not get proper results, because of the default token_pattern
in CountVectorizer:
token_pattern : ’(?u)bww+b’
string Regular expression denoting what constitutes a
“token”, only used if analyzer == 'word'. The default regexp select
tokens of 2 or more alphanumeric characters (punctuation is completely
ignored and always treated as a token separator)
In order for it to consider your numbers as words, you will need to change it so that it can accept single letters as words by doing this:
vectorizer = CountVectorizer(token_pattern=r"(?u)bw+b")
Then it should work. But now your numbers are changed into strings
It worked ,thank you very much
– Z Mario
Nov 19 at 12:31
add a comment |
up vote
3
down vote
accepted
You are using CountVectorizer
which requires an iterable of strings. Something like:
datas = ['First sentence',
'Second sentence', ...
...
'Yet another sentence']
But your data is a list of lists, which is why the error occurs. You need to make the inner lists as strings for the CountVectorizer to work. You can do this:
datas = [' '.join(map(str, x)) for x in datas]
This will result in datas
like this:
['1 2 4 6 7', '2 3', '5 6 8 3 5', '2', '93 23 4 5 11 3 5 2']
Now this form is consumable by CountVectorizer
. But even then you will not get proper results, because of the default token_pattern
in CountVectorizer:
token_pattern : ’(?u)bww+b’
string Regular expression denoting what constitutes a
“token”, only used if analyzer == 'word'. The default regexp select
tokens of 2 or more alphanumeric characters (punctuation is completely
ignored and always treated as a token separator)
In order for it to consider your numbers as words, you will need to change it so that it can accept single letters as words by doing this:
vectorizer = CountVectorizer(token_pattern=r"(?u)bw+b")
Then it should work. But now your numbers are changed into strings
It worked ,thank you very much
– Z Mario
Nov 19 at 12:31
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
You are using CountVectorizer
which requires an iterable of strings. Something like:
datas = ['First sentence',
'Second sentence', ...
...
'Yet another sentence']
But your data is a list of lists, which is why the error occurs. You need to make the inner lists as strings for the CountVectorizer to work. You can do this:
datas = [' '.join(map(str, x)) for x in datas]
This will result in datas
like this:
['1 2 4 6 7', '2 3', '5 6 8 3 5', '2', '93 23 4 5 11 3 5 2']
Now this form is consumable by CountVectorizer
. But even then you will not get proper results, because of the default token_pattern
in CountVectorizer:
token_pattern : ’(?u)bww+b’
string Regular expression denoting what constitutes a
“token”, only used if analyzer == 'word'. The default regexp select
tokens of 2 or more alphanumeric characters (punctuation is completely
ignored and always treated as a token separator)
In order for it to consider your numbers as words, you will need to change it so that it can accept single letters as words by doing this:
vectorizer = CountVectorizer(token_pattern=r"(?u)bw+b")
Then it should work. But now your numbers are changed into strings
You are using CountVectorizer
which requires an iterable of strings. Something like:
datas = ['First sentence',
'Second sentence', ...
...
'Yet another sentence']
But your data is a list of lists, which is why the error occurs. You need to make the inner lists as strings for the CountVectorizer to work. You can do this:
datas = [' '.join(map(str, x)) for x in datas]
This will result in datas
like this:
['1 2 4 6 7', '2 3', '5 6 8 3 5', '2', '93 23 4 5 11 3 5 2']
Now this form is consumable by CountVectorizer
. But even then you will not get proper results, because of the default token_pattern
in CountVectorizer:
token_pattern : ’(?u)bww+b’
string Regular expression denoting what constitutes a
“token”, only used if analyzer == 'word'. The default regexp select
tokens of 2 or more alphanumeric characters (punctuation is completely
ignored and always treated as a token separator)
In order for it to consider your numbers as words, you will need to change it so that it can accept single letters as words by doing this:
vectorizer = CountVectorizer(token_pattern=r"(?u)bw+b")
Then it should work. But now your numbers are changed into strings
edited Nov 19 at 9:13
answered Nov 19 at 9:04
Vivek Kumar
14.2k41849
14.2k41849
It worked ,thank you very much
– Z Mario
Nov 19 at 12:31
add a comment |
It worked ,thank you very much
– Z Mario
Nov 19 at 12:31
It worked ,thank you very much
– Z Mario
Nov 19 at 12:31
It worked ,thank you very much
– Z Mario
Nov 19 at 12:31
add a comment |
up vote
-1
down vote
Using our term frequency matrix, the idf weight for can be calculated like below.
# idf
( idf <- log( ncol(tf) / ( 1 + rowSums(tf != 0) ) ) )
Now that we have our matrix with the term frequency and the idf weight, we’re ready to calculate the full tf-idf weight. To do this matrix multiplication, we will also have to transform the idf vector into a diagonal matrix. Both calculations are shown below.
# diagonal matrix
( idf <- diag(idf) )
tf_idf <- crossprod(tf, idf)
colnames(tf_idf) <- rownames(tf)
tf_idf
For each vector v→, you divide it by its norm (length, magnitude). Calculation as below
# Note that normalization is computed "row-wise"
tf_idf / sqrt( rowSums( tf_idf^2 ) )
This doesn't look like Python at all.
– tripleee
Nov 19 at 8:32
but how to build frequency matrix ?
– Z Mario
Nov 19 at 8:47
Case of "R" stackoverflow.com/questions/43357603/… Case of Python stackoverflow.com/questions/41300583/…
– Amal Dominic
Nov 19 at 9:15
add a comment |
up vote
-1
down vote
Using our term frequency matrix, the idf weight for can be calculated like below.
# idf
( idf <- log( ncol(tf) / ( 1 + rowSums(tf != 0) ) ) )
Now that we have our matrix with the term frequency and the idf weight, we’re ready to calculate the full tf-idf weight. To do this matrix multiplication, we will also have to transform the idf vector into a diagonal matrix. Both calculations are shown below.
# diagonal matrix
( idf <- diag(idf) )
tf_idf <- crossprod(tf, idf)
colnames(tf_idf) <- rownames(tf)
tf_idf
For each vector v→, you divide it by its norm (length, magnitude). Calculation as below
# Note that normalization is computed "row-wise"
tf_idf / sqrt( rowSums( tf_idf^2 ) )
This doesn't look like Python at all.
– tripleee
Nov 19 at 8:32
but how to build frequency matrix ?
– Z Mario
Nov 19 at 8:47
Case of "R" stackoverflow.com/questions/43357603/… Case of Python stackoverflow.com/questions/41300583/…
– Amal Dominic
Nov 19 at 9:15
add a comment |
up vote
-1
down vote
up vote
-1
down vote
Using our term frequency matrix, the idf weight for can be calculated like below.
# idf
( idf <- log( ncol(tf) / ( 1 + rowSums(tf != 0) ) ) )
Now that we have our matrix with the term frequency and the idf weight, we’re ready to calculate the full tf-idf weight. To do this matrix multiplication, we will also have to transform the idf vector into a diagonal matrix. Both calculations are shown below.
# diagonal matrix
( idf <- diag(idf) )
tf_idf <- crossprod(tf, idf)
colnames(tf_idf) <- rownames(tf)
tf_idf
For each vector v→, you divide it by its norm (length, magnitude). Calculation as below
# Note that normalization is computed "row-wise"
tf_idf / sqrt( rowSums( tf_idf^2 ) )
Using our term frequency matrix, the idf weight for can be calculated like below.
# idf
( idf <- log( ncol(tf) / ( 1 + rowSums(tf != 0) ) ) )
Now that we have our matrix with the term frequency and the idf weight, we’re ready to calculate the full tf-idf weight. To do this matrix multiplication, we will also have to transform the idf vector into a diagonal matrix. Both calculations are shown below.
# diagonal matrix
( idf <- diag(idf) )
tf_idf <- crossprod(tf, idf)
colnames(tf_idf) <- rownames(tf)
tf_idf
For each vector v→, you divide it by its norm (length, magnitude). Calculation as below
# Note that normalization is computed "row-wise"
tf_idf / sqrt( rowSums( tf_idf^2 ) )
edited Nov 19 at 8:31
tripleee
87.1k12122177
87.1k12122177
answered Nov 19 at 8:25
Amal Dominic
12
12
This doesn't look like Python at all.
– tripleee
Nov 19 at 8:32
but how to build frequency matrix ?
– Z Mario
Nov 19 at 8:47
Case of "R" stackoverflow.com/questions/43357603/… Case of Python stackoverflow.com/questions/41300583/…
– Amal Dominic
Nov 19 at 9:15
add a comment |
This doesn't look like Python at all.
– tripleee
Nov 19 at 8:32
but how to build frequency matrix ?
– Z Mario
Nov 19 at 8:47
Case of "R" stackoverflow.com/questions/43357603/… Case of Python stackoverflow.com/questions/41300583/…
– Amal Dominic
Nov 19 at 9:15
This doesn't look like Python at all.
– tripleee
Nov 19 at 8:32
This doesn't look like Python at all.
– tripleee
Nov 19 at 8:32
but how to build frequency matrix ?
– Z Mario
Nov 19 at 8:47
but how to build frequency matrix ?
– Z Mario
Nov 19 at 8:47
Case of "R" stackoverflow.com/questions/43357603/… Case of Python stackoverflow.com/questions/41300583/…
– Amal Dominic
Nov 19 at 9:15
Case of "R" stackoverflow.com/questions/43357603/… Case of Python stackoverflow.com/questions/41300583/…
– Amal Dominic
Nov 19 at 9:15
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370715%2fhow-to-transform-the-data-and-calculate-the-tfidf-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What did you search for in order to solve this, and what did you find? What did you try, and why didn't it work?
– tripleee
Nov 19 at 8:33
I have put my code above
– Z Mario
Nov 19 at 8:43
Thanks for the code. Please include the full traceback still, though.
– tripleee
Nov 19 at 8:44
ok I have add the full traceback, I think my way is wrong ,but I don't know how to fix it
– Z Mario
Nov 19 at 8:52
Unfortunately, that doesn't look like a full traceback. Also
str(nodes[0])
in the traceback doesn't seem to correspond to anything in your question. You should probably review the guidance for how to create a Minimal, Complete, and Verifiable example.– tripleee
Nov 19 at 8:53