NameError: name 'count' is not defined(2) [closed] - python

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 days ago.
Improve this question
#twitter
from ckonlpy.tag import Twitter
twitter = Twitter()
print(journal['cleaned_text'][0])
print("="*30)
print(twitter.pos(journal['cleaned_text'][0],count('word')))
Traceback (most recent call last)
C:\Users\Public\Documents\ESTsoft\CreatorTemp\ipykernel_9264\3010786454.py in <module>
1 print(journal['cleaned_text'][0])
2 print("="*30)
----> 3 print(twitter.pos(journal['cleaned_text'][0],count('word')))
NameError: name 'count' is not defined
How can I fix this error?
Code that I worked on in another window before.
However, the following error code occurs when working in a new window.`

You need to replace the "," inside of the print for a "." for it to work.
Like this: print(twitter.pos(journal['cleaned_text'][0].count('word')))
Here is the doc for the count method. Hope this helps!

Related

python soup response parsing header and value [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed yesterday.
Improve this question
i have soup response text with multiple group and sub groups.
i want to get automatic all groups and their values .
how can i do it ?
In the end, I want to get the title and the value for each group. The best thing for me is for each group to have its values separately.
OrderedDict([('#id',
'boic'),
('mc:id',
'boic'),
('mc:ocb-conditions',
OrderedDict([('mc:rule-deactivated',
'true'),
('mc:international',
'true')])),
('mc:cb-actions',
OrderedDict([('mc:allow',
'false')]))])
My goal is to get to a state where I get the following output:
'#id','boic'
'mc:id','boic'
'mc:ocb-conditions'
'mc:rule-deactivated','true'
'mc:international', 'true'
'mc:cb-actions'
'mc:allow','false'
i try to use
' '.join(BeautifulSoup(soup_response, "html.parser").findAll(text=True))
and got all values But I'm missing the titles of the values.

Saving csv in specific json format [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
How do i save my csv into json , where column ="questions"
Particularly in this format
[
"What is dewa?" , "what is regulations?" ,"What is the fire rating for building having more than 2 basements?"
]
Right now I am getting my json is in this format
{"Question":{"0":"what is dewa?","1":"what is regulations?","2":"What is the fire rating for building having more than 2 basements?"}}
Code , for csv too json
import pandas as pd
read_csv = pd.read_csv(r'C:\Users\heba.fatima\Desktop\final-fire/answers.csv') # or delimiter = ';'
read_csv=read_csv[["Question"]]
read_csv.head()
read_csv.to_json (r'C:\Users\heba.fatima\Desktop\flaskapi\data\answers.json')
You can use orient argument for to_json:
read_csv['Question'].to_json(orient='values')
output:
["what is dewa?", "what is regulations?", "What is the fire rating for building having more than 2 basements?"]

A little confused with this python dictionary example [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
data = [{'name':'Albert','rel':'Head','unique_number': 101},
{'name':'Sheen','rel':'Head','unique_number': 201},
{'name':'Peter','rel':'Son','unique_number': 101},
{'name':'Chloe','rel':'Daughter','unique_number': 101}]
can you help me out in getting data like this? filtered on unique_number
updated_data = [
{'house_head':'Albert','members':['Peter','Chloe']},
{'house_head':'Sheen','members':[]}
]
The following should work:
numbers=set([i['unique_number'] for i in data])
dict={i:{'Head':'', 'members':[]} for i in numbers}
for i in data:
if i['rel']=='Head':
dict[i['unique_number']]['Head']=i['name']
else:
dict[i['unique_number']]['members'].append(i['name'])
new_data=[{'house_head':dict[i]['Head'], 'members':dict[i]['members']} for i in dict]

how to fetch only content from table by avoiding unwanted codes [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I was trying to fetch text content from table which works well but along with result it print unwanted codes
my code is here
searchitem = searchme.objects.filter(face = after) .values_list ("tale" , flat = True)
the contents are text
the result I receive is "querySet Prabhakaran seachitem"
but I only want o get result "Prabhakaran"
model is this
class searchme ( models.Model):
face = models.TextField()
tale = models.TextField ()
From the official django documentation :
A common need is to get a specific field value of a certain model instance. To achieve that, use values_list() followed by a get() call:
So use:
searchme.objects.values_list('tale', flat=True).get(face=after)

AttributeError: 'TextFileReader' object has no attribute 'get_chunck' [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I am trying to read a huge file lazily in with the pandas get_csv function. I want to access the first 5000 elements of a specified column. But I am getting the error I mentioned in my title.
#fetching data
train = pd.read_csv(os.path.join(dir,"Train.csv"),iterator = True)
test = pd.read_csv(os.path.join(dir,"Test.csv"),iterator = True)
Getting the parts of the data I need:
labels = np.array(train.get_chunk(5000))[:,3]
train = np.array(train.get_chunck(5000))[:,2]
test = np.array(test.get_chunk(5000))[:,2]
Error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-43-b164e8752510> in <module>()
1 labels = np.array(train.get_chunk(5000))[:,3]
----> 2 train = np.array(train.get_chunck(5000))[:,2]
3 test = np.array(test.get_chunk(5000))[:,2]
AttributeError: 'TextFileReader' object has no attribute 'get_chunck'
Apparently I am not allowed to do it like this? If not, how could I rewrite this to achieve what I am trying to achieve with this code?
get_chunck is a spelling error!
Try get_chunk instead of get_chunck.
get_chunck is the culprit ! get_chunk

Categories