Python Forum
getting unique values and counting amounts
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
getting unique values and counting amounts
#21
I expect that hyperlinks are not considered valid file paths. You would need to download the file or access it through a web package.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#22
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.
Reply
#23
(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 ☂ ⛄日本語の
Reply
#24
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.
Reply
#25
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.
Reply
#26
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.
Reply
#27
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Get an average of the unique values of a column with group by condition and assign it klllmmm 0 220 Feb-17-2024, 05:53 PM
Last Post: klllmmm
  Counting the values ​​in the dictionary Inkanus 7 3,516 Oct-26-2020, 01:28 PM
Last Post: Inkanus
  5 variants to invert dictionaries with non-unique values Drakax1 2 2,562 Aug-31-2020, 11:40 AM
Last Post: snippsat
  Finding Max and Min Values Associated with Unique Identifiers in Python ubk046 1 2,010 May-08-2020, 12:04 PM
Last Post: anbu23
  How to compare two columns and highlight the unique values of column two using pandas shubhamjainj 0 4,235 Feb-24-2020, 06:19 AM
Last Post: shubhamjainj
  Getting Unique values from LISTS aankrose 2 2,210 Oct-17-2019, 05:33 PM
Last Post: aankrose
  count unique values of a list with a list 3Pinter 2 4,820 Jul-05-2018, 11:52 AM
Last Post: 3Pinter
  code that takes inputs for user name amounts etc and then sends custom message shaumyabrata 5 5,246 Feb-12-2017, 11:37 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020