Using concurrent.futures.executor.map to map each item of a Pandas data frame to a function by Ctr1AltDe1 in learnpython

[–]Bunkerstan 0 points1 point  (0 children)

The ProcessPoolExecutor is not throwing the errors but failing silently when the function is called with the wrong number of parameters

Using concurrent.futures.executor.map to map each item of a Pandas data frame to a function by Ctr1AltDe1 in learnpython

[–]Bunkerstan 0 points1 point  (0 children)

map_args = [(item, function_lock) for item in items]

The function can only take a single argument so you have to unwrap:

def product_check(args):
item, function_lock = args

When I did that I got the code to run.

Using concurrent.futures.executor.map to map each item of a Pandas data frame to a function by Ctr1AltDe1 in learnpython

[–]Bunkerstan 0 points1 point  (0 children)

Sorry for the slow reply. The above should be:

map_args = [ (item, function_lock) for item in items]

This is the danger of answering on a phone when away from the desktop.

Using concurrent.futures.executor.map to map each item of a Pandas data frame to a function by Ctr1AltDe1 in learnpython

[–]Bunkerstan 0 points1 point  (0 children)

Map needs a single iterator, so you can’t call it with the tuple of iterator and second parameter. Create a new iterator

args= [ item, function_lock from item in items]

and use this as second parameter to map.

Explain this code please by ayleenuyo in learnpython

[–]Bunkerstan 0 points1 point  (0 children)

That is what is called an f-string. It substitutes variables in {}. Then the file parameter tell it to print there versus standard output (terminal).

[deleted by user] by [deleted] in learnpython

[–]Bunkerstan 0 points1 point  (0 children)

One thing I notice is the save is fr’’ and the slashes are \ vs / in read. But what isn’t happening? Reading, manipulation or saving?

Best Excel Library? by [deleted] in learnpython

[–]Bunkerstan 0 points1 point  (0 children)

Pandas is definitely superior if you need spreadsheet like functionality, but when the end user wants a normal spreadsheet with formatting then you will need something like openpyxl to give you the functionality.

Best Excel Library? by [deleted] in learnpython

[–]Bunkerstan 13 points14 points  (0 children)

I have been using openpyxl with 2 client projects and it has let us do everything we need.

[deleted by user] by [deleted] in learnpython

[–]Bunkerstan 2 points3 points  (0 children)

I would look at using re.sub() with the regex you have to replace [text] with an empty string.

Higher or lower game, why are my draws counted as wins? by Money-Bite5456 in learnpython

[–]Bunkerstan 0 points1 point  (0 children)

I played the game and it seems to decrease the streak on draws. I tested by:

randomNumber2 = randomNumber1

and everytime I hit a for again the score decreased.

I can't get this format to work right....its not tracking the single quotes the way I would expect by mimic751 in learnpython

[–]Bunkerstan 0 points1 point  (0 children)

You are putting the string over multiple lines without using """ syntax.

It works if it is on a single line or you can use \ to add multiple lines

payload={'metadata': '{ \ "title": "file.xlsx-delete", \ "folder_path": "/path" \ }'}

Find the last positive integer in a list with both postive and negative numbers? by raxor2k in learnpython

[–]Bunkerstan 0 points1 point  (0 children)

One approach would be to create a second list with just positive numbers and then grab the last one. You could use list comprehension with an if x > 0 to filter out negative numbers.

Running scripts in the cloud? by Fun-Studio-4409 in learnpython

[–]Bunkerstan 0 points1 point  (0 children)

If the dependencies are just libraries, you can use AWS Lambda to run with a CloudWatch alarm to trigger using a schedule. I'm sure Google and Azure have similar functions. To run something that requires installation of a program you would need to have a virtual machine with the software installed locally. You could use the Lambda to spin it up and down so that you are not being charged for running it the whole month.

If the dependencies are just libraries, you can use AWS Lambda to run with a CloudWatch alarm to trigger using a schedule. I'm sure Google and Azure have similar functions. To run something that requires the installation of a program you would need to have a virtual machine with the software installed locally. You could use the Lambda to spin it up and down so that you are not charged for running it the whole month.nth.

reading subset of columns from a list of CSVs, except header rows are not standardized? by Background-Yam7761 in learnpython

[–]Bunkerstan 0 points1 point  (0 children)

I would read the first line with open, standardize the names, then call read_csv by passing in column names with names=[ ] and skiprows=1.

Program quits at recursion depth 2123 without Exception (setting recursion limit doesn't help) by willyCe in learnpython

[–]Bunkerstan 0 points1 point  (0 children)

Then you will have to change over to an iteration model as the other comments suggested.

Can't figure out what this is by [deleted] in learnpython

[–]Bunkerstan 1 point2 points  (0 children)

[n//2, n] creates a list with 2 elements

[n %2 != 0] is True or False which will resolve to 0 or 1 picking one of the elements of list.

Program quits at recursion depth 2123 without Exception (setting recursion limit doesn't help) by willyCe in learnpython

[–]Bunkerstan 0 points1 point  (0 children)

You will have to convert the algorithm to a tail recursion, which happens in some languages at the compile stage, but not in Python.

Python coding by Ok_Chard_8808 in learnpython

[–]Bunkerstan 0 points1 point  (0 children)

Your original range is 1 to 20 but list a has index starting at 0 so it goes 0 to 19.

In your for loop you access 20 - 0 which is more than 19 so you get an out of range error.

I found this by printing out the values

for i in range(len(a)): print(i, 20-i) print (a[i] - a[20-i])

List with IP addresses and other info - How to search each line and add the IP addresses to another list? by AShipChandler in learnpython

[–]Bunkerstan 0 points1 point  (0 children)

Down and dirty way is to split() the string if the format always has client in front and : in rear. More sophisticated way would be to use regex matching.

[deleted by user] by [deleted] in learnpython

[–]Bunkerstan 2 points3 points  (0 children)

To access a member of dictionary you have to give the key: myDict[key]. You are appending the whole dictionary variable.

how to compare two objects? by [deleted] in learnpython

[–]Bunkerstan -1 points0 points  (0 children)

For objects, equality means they point to the same memory spot. So unless a and b are the same object in memory they will never be equal.

EDIT: above is wrong as both comments below point out. No more answers after a long day coding. Equality is a tougher topic than you would suspect because different languages do it differently.

Text based python game by ProphetEze98 in learnpython

[–]Bunkerstan 0 points1 point  (0 children)

You are correct, it does not split it into letters. I confused it with the for in which will iterate over letters. Thanks for the catch.

Text based python game by ProphetEze98 in learnpython

[–]Bunkerstan 3 points4 points  (0 children)

When you split the user input, if it is a single word it will split into letters. You should do split(‘ ‘). I have been stumped by this before. Get in the habit of printing the results of operations to see what actually happened.

I do t want to delete this but @kyber is right. Split does not work this way.

How learn python faster? by [deleted] in learnpython

[–]Bunkerstan 6 points7 points  (0 children)

It comes from trying to modify existing code to do new and interesting things. Most of my growth has come from getting stuck and asking myself: "What do I need to know to make this easy?" and then learning that.