Re: [Tutor] Iteration issues
On 2018-05-10, Albert-Jan Roskam wrote: > If a punctuation symbol is in your string: Replace that symbol > with an empty string. > >=>>> maybe something like > > import re > no_interpunction = re.sub("[%s]" % re.escape(string.punctuation), '', > sentence) str.translate can be used instead of re. # Compute only once somewhere punctuation_removal_table = str.maketrans({c: None for c in string.punctuation}) no_interpunction = sentence.translate(punctuation_removal_table) Unfortunately you'll remove all the apostrophes and dashes, both of which could be considered parts of words. -- Neil Cerutti ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] ImportError: No module named openpyxl.workbook
Hi, I am trying to write the pandas dataframe to excel but it shows following error: Error: from openpyxl.workbook import Workbook ImportError: No module named openpyxl.workbook I am using only pandas however it still works fine on one computer having openpyxl already installed eventhough i am not using openpyxl in the program while shows above error on other computer where openpyxl is not installed. both computers are running on the same python version. my code below: import pandas as pd writer = pd.ExcelWriter('summary.xlsx') df.to_excel(writer, index=False) writer.save() any help appreciated. Thank you, Paresh ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Question about a python finction
Hello, Is there a function that allows you to grab the numbers between two numbers? Eg. If you input the numbers 1 and 4 To make a list like this [1,2,3,4] Thank you for you’re time Sent from my iPhone ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question about a python finction
On 09/05/18 13:14, kevin hulshof wrote: Hello, Is there a function that allows you to grab the numbers between two numbers? Eg. If you input the numbers 1 and 4 To make a list like this [1,2,3,4] Thank you for you’re time Seems like 'range' should fit your needs https://docs.python.org/3/library/stdtypes.html#typesseq -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question about a python finction
> On May 9, 2018, at 07:14, kevin hulshof wrote: > > Hello, > > Is there a function that allows you to grab the numbers between two numbers? > > Eg. If you input the numbers 1 and 4 > To make a list like this [1,2,3,4] One option is range range(1,5) >>> range(1,5) [1, 2, 3, 4] https://docs.python.org/2/library/functions.html#range — David Rock da...@graniteweb.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] ImportError: No module named openpyxl.workbook
On 11/05/18 01:43, Pareshkumar Panchal wrote: > Error: > from openpyxl.workbook import Workbook > ImportError: No module named openpyxl.workbook > > I am using only pandas however it still works fine on one computer having > openpyxl already installed eventhough i am not using openpyxl in the > program while shows above error on other computer where openpyxl is not > installed. So install openpyxl? The error says there are no module named openpyxl.workbook That seems very likely if openpyxl is mossing. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Iteration issues
Op 11 mei 2018 21:43 schreef Neil Cerutti : On 2018-05-10, Albert-Jan Roskam wrote: > If a punctuation symbol is in your string: Replace that symbol > with an empty string. > >=>>> maybe something like > > import re > no_interpunction = re.sub("[%s]" % re.escape(string.punctuation), '', > sentence) str.translate can be used instead of re. # Compute only once somewhere punctuation_removal_table = str.maketrans({c: None for c in string.punctuation}) no_interpunction = sentence.translate(punctuation_removal_table) Unfortunately you'll remove all the apostrophes and dashes, both of which could be considered parts of words. Nice, I did not think of str.translate. It appears to be the fastest (and most readable) method, though a compiled regex is also pretty fast: http://bbs.bugcode.cn/t/3320#IDb95ffe2791c1a59f0ac8175905705f34 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor