I have dataframe as per below Country: China, China, China, United Kingdom, United Kingdom,United Kingdom Country code: CN, CN, CN, UK, UK, UK Port Name: Yantian, Shekou, Quanzhou, Plymouth, Cardiff, Bird port I want to remove the duplicates in the first two columns, only keep as: Country: China, , , United K…
Tag: python
Detect if all pixels in an image are zero/black (Maya Python)
Newbie. Using the following code to check if a grayscale image (a mask texture in Maya) has all black pixels in the RGB channels (meaning it is empty). This works, but is a bit slow on large images (2048×2048 is around 15 seconds). Looking for how I can speed this up / do this more efficiently. EDIT: Thi…
How to get prior close when you have all stocks in a single DF?
Sorry for the noob question. I have a bunch of stocks in a sqlite3 database: When I print the df, it gives me the following (where each stock_id refers to a unique stock, e.g APPL): I need to target each unique stock_id individually, and get the prior close. I know if each stock was in its own separate datafr…
how to run python script in cmd
I wrote a small project to render video in the console. I used PyCharm, and if I run the code in it everything works as it should, but how do I run the file so that the result is displayed on the console? Answer Judging from your usage of mode con, you must be on Windows. Assuming you have Python
Creating time delta diff column based on groupby id
I have the following sample df I want to groupby Id, and get the timedelta difference between the timestamps, i manage to get something similar to the wanted series. Through this code. Although, it is taking quite a long time, is there a way to do it more efficiently? Wanted series Answer here is one way abou…
Apply function to all columns of data frame python
I have two dfs AVERAGE_CALL_DURATION AVERAGE_DURATION CHANGE_OF_DETAILS 267 298 0 0 421 609.33 0.33 330 334 0 0 240.5 666.5 0 628 713 0 0 and AVERAGE_CALL_DURATION AVERAGE_DURATION CHANGE_OF_DETAILS -5.93 -4.95 0.90 593.50 595.70 1.00 I want to return 1 if the xx column contains the range within NoC_c (where …
ValueError: Invalid fill method. Expecting pad (ffill) or backfill (bfill). Got nearest
I have this df: And when I try to run this interpolation: pmms_df.interpolate(method = ‘nearest’, inplace = True) I get ValueError: Invalid fill method. Expecting pad (ffill) or backfill (bfill). Got nearest I read in this post that pandas interpolate doesn’t do well with the time columns, s…
Install newer version of sqlite3 on AWS Lambda for use with Python
I have a Python script running in a Docker container on AWS Lambda. I’m using the recommended AWS image (public.ecr.aws/lambda/python:3.9), which comes with SQLite version 3.7.17 (from 2013!). When I test the container locally on my M1 Mac, I see this: However, I use newer SQLite features, so I need to …
Is there any python way to repeat values of a row combining them in a column with a list type?
I have two dataframes, the first is this one, created with the following code: The second one is the following: What I need to do is to add a column to the second data frame that contains lists of values taken from the first data frame. I will show it and then explain it with words: The lists should contain
Django test uses wrong database in some cases
I try to setup my Django tests, and I noticed that when I run all tests TestRunner uses correct test database (for all aliases): docker-compose exec my_project python manage.py test –keepdb But when I run tests for specific module, it uses the original database: docker-compose exec my_project python man…