Python Forum
getting unique values and counting amounts - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: getting unique values and counting amounts (/thread-16483.html)

Pages: 1 2 3


RE: getting unique values and counting amounts - ichabod801 - Mar-07-2019

I expect that hyperlinks are not considered valid file paths. You would need to download the file or access it through a web package.


RE: getting unique values and counting amounts - Truman - Mar-07-2019

with open(os.path.abspath("c:/Python36/kodovi/inauguration.txt"), "r", encoding='latin-1') as file:
    text = file.read()
print(text[0:1000])
Yes, this works.


RE: getting unique values and counting amounts - snippsat - Mar-08-2019

(Mar-07-2019, 11:22 PM)Truman Wrote: Yes, this works.
That's different is a file path in you other post it's a url.
Then need a web package as mention bye @ichabod801,then it's of course Requests you should use.
import requests
import os

url = 'http://pythonscraping.com/files/inaugurationSpeech.txt'
file_name = os.path.basename(url)
response =  requests.get(url)
with open(file_name,'wb') as f:
    f.write(response.content)
Do not use encoding='latin-1' the rule is simple do text show without any problem in Python 3.
Then take it out/in with encoding='utf-8'.
Taking data into Python 3 may sometime require other encoding that utf-8.
s = 'Crème and Spicy jalapeño ☂ ⛄日本語のキ'
# Out
with open('unicode.txt', 'w', encoding='utf-8') as f_out:
    f_out.write(s)

# Back in
with open('unicode.txt', encoding='utf8') as f:
    data = f.read()
    print(data)
Output:
Crème and Spicy jalapeño ☂ ⛄日本語の



RE: getting unique values and counting amounts - Truman - Mar-14-2019

http://www.nltk.org/book/ch00.html

I've just started reading this book. Are you maybe familiar if solutions to the problems given in the book can be found on github?
I found this one>
https://github.com/JuliaNeumann/nltk_book_exercises

wondering if there's an 'official' one.


RE: getting unique values and counting amounts - Larz60+ - Mar-14-2019

I purchased a copy of this book several years ago.

I just took a look at my epub version of the book, and I always store any example code in the same location as my books.
I have none, so my guess is that there is no 'official' download available.
However that's not an issue with this text as almost all of the example code is done using interactive python, and where not,
the code can easily be cut and pasted.

So, my guess is you use Julia Neumann's version (which I just downloaded), Thanks for the link!

** Added Note ** I'll check into my O'reilly account and see if an official version has been added.


RE: getting unique values and counting amounts - Larz60+ - Mar-14-2019

I actually purchased my copy in Feb of 2015.
But O'Reilly keeps all pertinent data updated on every one of their books, and still no 'official' code download. So there you go.
Again the link you posted looks like a good one.


RE: getting unique values and counting amounts - Truman - Mar-15-2019

Yet, I decided to finish Web Scraping with Python ( I'm on Markov models right now ) by Mitchell before I start a new book. And in the meantime maybe I should start some real project.