Skip to main content

Posts

Get pandas groupby().apply() result as a series of dataframes

I have a pandas dataframe on which I call df.groupby('foo').apply(bar) where bar is a function that return a dataframe. I want the result to be a series with index of the different values of foo and elements being the different dataframes returned by bar (the inuitvie result as this is how groupby().apply() behaves with all other return types of bar ). However instead I get a multi index dataframe with the first index being the different values of foo and the second index being the index of the dataframes that are returned by bar . How can I convert it to the desired format? source https://stackoverflow.com/questions/76614666/get-pandas-groupby-apply-result-as-a-series-of-dataframes

I want to draw a path on the given image using @shopify/reactnative-skia and then save the drawn part into an image

I want to draw a path on the given image using @shopify/reactnative-skia and then save the drawn part into an image as a clip but its not getting the correct clip image, here is the sample code; const surface = Skia.Surface.MakeOffscreen( canvasSize.width, canvasSize.height ); const currentCanvas = surface?.getCanvas(); const bounds = path.getBounds(); const paint = Skia.Paint(); paint.setAntiAlias(false); currentCanvas?.drawImageRect( image, Skia.XYWHRect(0, 0, image.width(), image.height()), Skia.XYWHRect(0, 0, canvasSize.width, canvasSize.height), paint ); currentCanvas?.save(); const clipImage = surface?.makeImageSnapshot(bounds); canvasSize.width and canvasSize.height is the screen width and height. And here is the base image: And cut part size: Via Active questions tagged javascript - Stack Overflow https://ift.tt/Z2g0THL

Memory leak and stuck in deadlock during AWS boto multithread download

This method is used for downloading a single file just need to pass object name and bucket name. def download_file(self, object_name: str, bucket_name: str = None, local_directory_path: Path = None, config=None, include_prefix_path: bool = True, minimal_logging: bool = True): """Download an S3 object to a file. Parameters ---------- bucket_name : str S3 bucket name prefix : str AWS S3 path from where you need to fetch the aws s3 ls dump local_directory_path : Path Directory where files need to be downloaded """ # Creating S3 client with our access key if self.s3_client is None: self.config_dict = self._config_read_utility(read_aws=True, read_audit=True) self.client_config = botocore.config.Config(max_pool_connections=50) self.s3_client = boto3.client('s3', aws_access_key_id=self.config_dict['aws_acc

how can I end the program based on the user's input?

I am trying to make a calculator using functions, but I am really not sure what am I doing wrong here. When the user types n/N the program does not end but continues from the else statement in operation_outcome() function. Seems the next_example() function works fine when the user wants another example, but I am not sure either if the code is written proper way here def enter_number(num, error): notEntered = True while notEntered: try: num = float(input(num)) notEntered = False except ValueError: print(error) else: return num def operation_outcome(first_num, second_num, choice, error): notEntered = True while notEntered: print("1. addition") print("2. subtraction") print("3. multiplication") print("4. division") try: choice = int(input(choice)) if choice >= 1 and choice <= 4:

Selenium allow redirect

Selenium doesn't load the page if it gets redirected before the page loads. The error is Message: unknown error: net::ERR_SOCKS_CONNECTION_FAILED Here is a simple selenium code from selenium import webdriver browser = webdriver.Chrome() browser.get('http://loginrequired.com/') Selenium wouldn't load the page, because the website immideately redirects us to the other page. How do I let Selenium to ignore the redirection and follow all next steps on the redirected page? This website is takes for the example purpose, so the answer would not be simply to try to get to the redirected page immideatly. source https://stackoverflow.com/questions/76607448/selenium-allow-redirect

pydrive2: Is Authorize() needed after Refresh()?

I'm writing a function that logs in a user to their Google Drive using OAuth 2.0. It returns the authenticated drive object. Here's my code: def login_with_account(): gauth = GoogleAuth() if 'credentials.json' in os.listdir(): gauth.LoadCredentialsFile("credentials.json") if gauth.access_token_expired: gauth.Refresh() else: gauth.Authorize() else: gauth.LocalWebserverAuth() gauth.SaveCredentialsFile("credentials.json") drive = GoogleDrive(gauth) return drive My question is: Do I need to Authorize() after Refresh() as well or is this enough? documentation link to Refresh() , can't find anything specific in the docs https://docs.iterative.ai/PyDrive2/pydrive2/#pydrive2.auth.GoogleAuth.Refresh source https://stackoverflow.com/questions/76600330/pydrive2-is-authorize-needed-after-refresh