on generating combinations among a variable list of lists
Say we have [1,3,5,7], [2,3], [1,10]. I'd like to generate [1,2,1] [1,2,10] [1,3,1] [1,3,10] [3,2,1] [3,2,10] [3,3,1] [3,3,10] [5, ...] ... [7,3,10] The number of input lists is variable. The example shows three lists, but there could be only one or ten lists or any other number of lists. I looked at itertools. There doesn't seem to be any procedure ready for this. I might have to combine some of them but I'm not yet sure how. -- https://mail.python.org/mailman/listinfo/python-list
[RELEASE] Python 3.7.8 and 3.6.11 now available - last 3.7.x bugfix release
https://discuss.python.org/t/python-3-7-8-and-3-6-11-now-available-last-3-7-x-bugfix-release/4583 -- Ned Deily [email protected] -- [] -- https://mail.python.org/mailman/listinfo/python-list
Re: on generating combinations among a variable list of lists
Boris Dorestand wrote: > Say we have [1,3,5,7], [2,3], [1,10]. I'd like to generate > > [1,2,1] > [1,2,10] > [1,3,1] > [1,3,10] > [3,2,1] > [3,2,10] > [3,3,1] > [3,3,10] > [5, ...] > ... > [7,3,10] > > The number of input lists is variable. The example shows three lists, > but there could be only one or ten lists or any other number of lists. > > I looked at itertools. There doesn't seem to be any procedure ready for > this. I might have to combine some of them but I'm not yet sure how. itertools.product() seems to do what you want: >>> for t in itertools.product([1,3,5,7], [2,3], [1,10]): ...print(t) ... (1, 2, 1) (1, 2, 10) (1, 3, 1) (1, 3, 10) (3, 2, 1) (3, 2, 10) (3, 3, 1) (3, 3, 10) (5, 2, 1) (5, 2, 10) (5, 3, 1) (5, 3, 10) (7, 2, 1) (7, 2, 10) (7, 3, 1) (7, 3, 10) If you need lists instead of tuples convert them >>> list(t) [7, 3, 10] To pass a varying number of lists use a list of lists and a star argument: >>> lists = [[[1, 2], [3, 4]], [[10, 20, 30], [40, 50]]] >>> for item in lists: ... print(list(itertools.product(*item))) ... [(1, 3), (1, 4), (2, 3), (2, 4)] [(10, 40), (10, 50), (20, 40), (20, 50), (30, 40), (30, 50)] -- https://mail.python.org/mailman/listinfo/python-list
Assign Excel cell value from Datepicker widget Selection using Python
When I run the python code I should be able to open my Excel and when I click
on one Excel cell I should have my datepicker widget popped up and I should be
able to select any date from my datepicker widget as my Excel cell value
Tried below code but in vain: (Used jupyter Notebook)
from ipywidgets import widgets
from openpyxl import *
wb = load_workbook('My_Excel.xlsx')
worksheet = wb.active
worksheet['B1'] = 'Datepicker'
worksheet['B2'] = widgets.DatePicker()
wb.save('My_Excel.xlsx')
wb.close()
Error Occured: ValueError: Cannot convert DatePicker(value=None) to Excel
--
https://mail.python.org/mailman/listinfo/python-list
Re: on generating combinations among a variable list of lists
Peter Otten <[email protected]> writes: > Boris Dorestand wrote: > >> Say we have [1,3,5,7], [2,3], [1,10]. I'd like to generate >> >> [1,2,1] >> [1,2,10] >> [1,3,1] >> [1,3,10] >> [3,2,1] >> [3,2,10] >> [3,3,1] >> [3,3,10] >> [5, ...] >> ... >> [7,3,10] >> >> The number of input lists is variable. The example shows three lists, >> but there could be only one or ten lists or any other number of lists. >> >> I looked at itertools. There doesn't seem to be any procedure ready for >> this. I might have to combine some of them but I'm not yet sure how. > > itertools.product() seems to do what you want: > for t in itertools.product([1,3,5,7], [2,3], [1,10]): > ...print(t) > ... > (1, 2, 1) > (1, 2, 10) > (1, 3, 1) > (1, 3, 10) > (3, 2, 1) > (3, 2, 10) > (3, 3, 1) > (3, 3, 10) > (5, 2, 1) > (5, 2, 10) > (5, 3, 1) > (5, 3, 10) > (7, 2, 1) > (7, 2, 10) > (7, 3, 1) > (7, 3, 10) That's precisely it. I missed product. Thanks! > If you need lists instead of tuples convert them > list(t) > [7, 3, 10] > > To pass a varying number of lists use a list of lists and a star argument: > lists = [[[1, 2], [3, 4]], [[10, 20, 30], [40, 50]]] for item in lists: > ... print(list(itertools.product(*item))) > ... > [(1, 3), (1, 4), (2, 3), (2, 4)] > [(10, 40), (10, 50), (20, 40), (20, 50), (30, 40), (30, 50)] The star-syntax I didn't even know. And it was very useful. Thank you! -- https://mail.python.org/mailman/listinfo/python-list
Re: Assign Excel cell value from Datepicker widget Selection using Python
On 29/06/20 3:04 AM, [email protected] wrote: When I run the python code I should be able to open my Excel and when I click on one Excel cell I should have my datepicker widget popped up and I should be able to select any date from my datepicker widget as my Excel cell value Tried below code but in vain: (Used jupyter Notebook) from ipywidgets import widgets from openpyxl import * wb = load_workbook('My_Excel.xlsx') worksheet = wb.active worksheet['B1'] = 'Datepicker' worksheet['B2'] = widgets.DatePicker() wb.save('My_Excel.xlsx') wb.close() Error Occured: ValueError: Cannot convert DatePicker(value=None) to Excel Do you know what comes back from the DatePicker() and is it suitable for this purpose? Recommend capturing it to a variable, and then printing its value (and type(), if necessary) to be sure of the facts... Let us know how you get on... -- Regards =dn -- https://mail.python.org/mailman/listinfo/python-list
Re: Assign Excel cell value from Datepicker widget Selection using Python
Datepicker is returning two different types. before date change its and after change its -- https://mail.python.org/mailman/listinfo/python-list
Re: Assign Excel cell value from Datepicker widget Selection using Python
Do we have any other to achive my query -- https://mail.python.org/mailman/listinfo/python-list
Re: Assign Excel cell value from Datepicker widget Selection using Python
Is there any other way to achieve my query? -- https://mail.python.org/mailman/listinfo/python-list
Re: Assign Excel cell value from Datepicker widget Selection using Python
[email protected] writes: > When I run the python code I should be able to open my Excel and when > I click on one Excel cell I should have my datepicker widget popped up > and I should be able to select any date from my datepicker widget as > my Excel cell value > > Tried below code but in vain: (Used jupyter Notebook) > > from ipywidgets import widgets > from openpyxl import * > > wb = load_workbook('My_Excel.xlsx') > worksheet = wb.active > worksheet['B1'] = 'Datepicker' > worksheet['B2'] = widgets.DatePicker() > wb.save('My_Excel.xlsx') > wb.close() > Error Occured: ValueError: Cannot convert DatePicker(value=None) to Excel You might be asking too much from the tools. Unless openpyxl has some special knowledge of ipywidgets, what you're looking for won't work. ipywidgets has web-based components, that work from web browsers. You can use the cell data validation features to restrict the B2 cell to a valid date value, and the cell formatting ability to set the visual representation to a date, but that will not be sufficient to turn it into a date picker. You will have to deal with VBA or form components to do that. I'm not aware of such capabilities in the various xlsx writing libraries. -- regards, kushal -- https://mail.python.org/mailman/listinfo/python-list
Re: Assign Excel cell value from Datepicker widget Selection using Python
On 29/06/20 6:01 AM, [email protected] wrote: Datepicker is returning two different types. before date change its and after change its Well done! When it is printed, the date probably makes sense (to us), and the debug-print has given you the opportunity to make sure the data is exactly what is required! Now consider the 'second half' of the process: which data-type the Excel interface requires. Given the original err.msg, a conversion function may be helpful, eg str() https://docs.python.org/3/library/string.html Successful? -- Regards =dn -- https://mail.python.org/mailman/listinfo/python-list
Re: I need to study Python
While there are a number of answers here which have a point, I'd first ask why do you want/need to study Python? Because, if you need it for something specific, you might want to focus on learning exactly what you need. In lack of an answer to that question, I'd recommend this: - as a newbie you need the basics first. There is a free interactive course here: https://www.codecademy.com/learn/learn-python-3 they'll give you the basic programming experience, without you having to set up any kind of programming environment, which is the first task with potential to scare away a beginner (depending on how ambitiously the environment is built up) - After that I'd give a plus one for the project based approach mentioned by J.Pic. If you however want to get a hands-on overview of what you can do with Python, go with a course that encompases a number of projects, if possible non-trivial ones. On Udemy you can find a number of such, I like this one: https://www.udemy.com/course/the-python-mega-course/ (make sure to purchase it for around 10$, when they are giving a discount, which is almost every week) - Finally, if you want to add some academic rigor and good programming practices, here's a free course by MIT: https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/lecture-videos/index.htm >From there on, things to learn are infinite, I'm afraid, but you'd definitely not be a noob any more. Or, at least, the best educated noob on the planet! Am Fr., 26. Juni 2020 um 01:49 Uhr schrieb : > Hey, I'm a completely noob. > I want to learn python, how can i or where can i study python? > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Does this dataframe look correct?
linux mint 19.3, python 3.6
I wrote a program to download stock info from yahoo using yfinance. I
have been running it unchanged for the past 3 months, today it gave an
error. When looping through a list of stocks the error is random, never
the same position in the list.
I wrote the following little test script to show the error:
import yfinance as yf
import pandas as pd
day = '2020-06-25'
aapl = yf.Ticker('AAPL')
hist = aapl.history(start=day)
print(hist)
close = hist.loc[day]['Close']
I ran it 10 times 8 times I got a dataframe and 2 times I got the error
shown below:
(env36) jfb@jims-mint18 ~ $ /home/jfb/EVs/env36/bin/python3
/home/jfb/Dev/Python/test_yfinance.py
OpenHigh Low CloseVolume
Date
2020-06-25 360.70 365.00 357.57 364.84 34380600
2020-06-26 364.41 365.32 353.02 353.63 51270100
(env36) jfb@jims-mint18 ~ $ /home/jfb/EVs/env36/bin/python3
/home/jfb/Dev/Python/test_yfinance.py
Traceback (most recent call last):
File "/home/jfb/Dev/Python/test_yfinance.py", line 13, in
hist = aapl.history(start=day)
File
"/home/jfb/EVs/env36/lib/python3.6/site-packages/yfinance/base.py", line
155, in history
data = data.json()
File
"/home/jfb/EVs/env36/lib/python3.6/site-packages/requests/models.py",
line 897, in json
return complexjson.loads(self.text, **kwargs)
File
"/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/__init__.py",
line 518, in loads
return _default_decoder.decode(s)
File
"/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/decoder.py",
line 370, in decode
obj, end = self.raw_decode(s)
File
"/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/decoder.py",
line 400, in raw_decode
return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I don't know pandas that well. My only contact with it is when a module
I am using depends on it. So does the dataframe look correct?
The error complains of line 1, column 1. Just looking at the dataframe
it looks like Date is on a different line from the rest of the headers
or is that just the result of being printed in the terminal?
On the yfinance github issues page there were a few people reporting
this error. A couple of people reported a work around using try/except.
It worked for some people and not others. It didn't work for me.
I'd appreciate any advice you could give.
Thanks, Jim
--
https://mail.python.org/mailman/listinfo/python-list
Re: Does this dataframe look correct?
On 2020-06-28 23:11, Jim wrote:
linux mint 19.3, python 3.6
I wrote a program to download stock info from yahoo using yfinance. I
have been running it unchanged for the past 3 months, today it gave an
error. When looping through a list of stocks the error is random, never
the same position in the list.
I wrote the following little test script to show the error:
import yfinance as yf
import pandas as pd
day = '2020-06-25'
aapl = yf.Ticker('AAPL')
hist = aapl.history(start=day)
print(hist)
close = hist.loc[day]['Close']
I ran it 10 times 8 times I got a dataframe and 2 times I got the error
shown below:
(env36) jfb@jims-mint18 ~ $ /home/jfb/EVs/env36/bin/python3
/home/jfb/Dev/Python/test_yfinance.py
OpenHigh Low CloseVolume
Date
2020-06-25 360.70 365.00 357.57 364.84 34380600
2020-06-26 364.41 365.32 353.02 353.63 51270100
(env36) jfb@jims-mint18 ~ $ /home/jfb/EVs/env36/bin/python3
/home/jfb/Dev/Python/test_yfinance.py
Traceback (most recent call last):
File "/home/jfb/Dev/Python/test_yfinance.py", line 13, in
hist = aapl.history(start=day)
File
"/home/jfb/EVs/env36/lib/python3.6/site-packages/yfinance/base.py", line
155, in history
data = data.json()
File
"/home/jfb/EVs/env36/lib/python3.6/site-packages/requests/models.py",
line 897, in json
return complexjson.loads(self.text, **kwargs)
File
"/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/__init__.py",
line 518, in loads
return _default_decoder.decode(s)
File
"/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/decoder.py",
line 370, in decode
obj, end = self.raw_decode(s)
File
"/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/decoder.py",
line 400, in raw_decode
return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I don't know pandas that well. My only contact with it is when a module
I am using depends on it. So does the dataframe look correct?
The error complains of line 1, column 1. Just looking at the dataframe
it looks like Date is on a different line from the rest of the headers
or is that just the result of being printed in the terminal?
On the yfinance github issues page there were a few people reporting
this error. A couple of people reported a work around using try/except.
It worked for some people and not others. It didn't work for me.
I'd appreciate any advice you could give.
It's complaining about the JSON data that it's getting. What does that
data look like when it complains?
It might be that there's some kind of limit to how often you can get the
data and it's trying to tell you that, but you're not expecting anything
back except the data.
You could add some temporary code at line 897 of
"/home/jfb/EVs/env36/lib/python3.6/site-packages/requests/models.py" to
save the data to a file just before the decoding. Remember to make a
backup copy of any source file that you modify!
--
https://mail.python.org/mailman/listinfo/python-list
Re: Does this dataframe look correct?
On 6/28/20 8:53 PM, MRAB wrote:
On 2020-06-28 23:11, Jim wrote:
linux mint 19.3, python 3.6
I wrote a program to download stock info from yahoo using yfinance. I
have been running it unchanged for the past 3 months, today it gave an
error. When looping through a list of stocks the error is random, never
the same position in the list.
I wrote the following little test script to show the error:
import yfinance as yf
import pandas as pd
day = '2020-06-25'
aapl = yf.Ticker('AAPL')
hist = aapl.history(start=day)
print(hist)
close = hist.loc[day]['Close']
I ran it 10 times 8 times I got a dataframe and 2 times I got the error
shown below:
(env36) jfb@jims-mint18 ~ $ /home/jfb/EVs/env36/bin/python3
/home/jfb/Dev/Python/test_yfinance.py
Open High Low Close Volume
Date
2020-06-25 360.70 365.00 357.57 364.84 34380600
2020-06-26 364.41 365.32 353.02 353.63 51270100
(env36) jfb@jims-mint18 ~ $ /home/jfb/EVs/env36/bin/python3
/home/jfb/Dev/Python/test_yfinance.py
Traceback (most recent call last):
File "/home/jfb/Dev/Python/test_yfinance.py", line 13, in
hist = aapl.history(start=day)
File
"/home/jfb/EVs/env36/lib/python3.6/site-packages/yfinance/base.py", line
155, in history
data = data.json()
File
"/home/jfb/EVs/env36/lib/python3.6/site-packages/requests/models.py",
line 897, in json
return complexjson.loads(self.text, **kwargs)
File
"/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/__init__.py",
line 518, in loads
return _default_decoder.decode(s)
File
"/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/decoder.py",
line 370, in decode
obj, end = self.raw_decode(s)
File
"/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/decoder.py",
line 400, in raw_decode
return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1
(char 0)
I don't know pandas that well. My only contact with it is when a module
I am using depends on it. So does the dataframe look correct?
The error complains of line 1, column 1. Just looking at the dataframe
it looks like Date is on a different line from the rest of the headers
or is that just the result of being printed in the terminal?
On the yfinance github issues page there were a few people reporting
this error. A couple of people reported a work around using try/except.
It worked for some people and not others. It didn't work for me.
I'd appreciate any advice you could give.
It's complaining about the JSON data that it's getting. What does that
data look like when it complains?
It might be that there's some kind of limit to how often you can get the
data and it's trying to tell you that, but you're not expecting anything
back except the data.
You could add some temporary code at line 897 of
"/home/jfb/EVs/env36/lib/python3.6/site-packages/requests/models.py" to
save the data to a file just before the decoding. Remember to make a
backup copy of any source file that you modify!
I don't think it is a limit problem. It happened the first time I ran
the script after a week of not using it. I am only geting info on 33
stocks and I know that people use this module to get info on 100's of
stocks.
Anyway I was wrong about the try/except not solving the problem. I made
a mistake in the try/except and when I corrected it, like a dummy, I
never saved the change before running it again.
I will use your suggestions to see if I can figure out the root cause of
the problem. as before today it ran for months with no errors. Sorry for
taking up the lists time with my mistake and thanks for your help.
Regards, Jim
--
https://mail.python.org/mailman/listinfo/python-list
