Say I have the following list of list of names: I want to return only the “Matts” in the list, but I also want to maintain the list of list structure. So I want to return: I’ve something like this, but this will append everthting together in one big list: I know something like this is possib…
ipykernel (Jupyter notebook/labs) cannot import name ”filefind” from traitlets.utils
I installed Jupyter notebook and labs on and EC2 instance and for some reason I get the following error: ImportError: cannot import name ‘filefind’ from ‘traitlets.utils’ (/usr/lib/python3/dist-packages/traitlets/utils/init.py) Jupyter opens fine in the browser but I can’t seem t…
How to fix Jupyter extension activation failed when opening python files?
I installed python lately on my macos system and when I try to open a python file I see this error popup about Jupyter extension : Answer Just ran into this today (I’m on MacOS for my work computer). In my case, upgrading to the pre-release version of the Jupyter extension (v2022.5.1001281006) solved it…
How can I label my axis after it print out all the data and mark for each data?
The coding below is my code. I would like to label the axis after it print all the data and the mark for each data. I don’t know why the label name only display at the begin. The content of the Surface.txt is Answer You can accomplish that by also adding the set_label commands inside the def animate() f…
How do I use Python AST module to obtain all targets and value for assignment nodes?
Similar unanswered question: Python AST – How to see value of assign node? I am trying to obtain the assignments statements in a file. Example: and form them into a dictionary like so: I only want the Assigns with value and target, no call objects. The AST module is very difficult to understand and I wo…
Python function make parameter mandatory if another parameter is passed
I have a function in Python as Is there a way to ensure that if the user passes the value of the parameter b it is necessary to pass the parameter c to myfunc? Answer You can write a simple if condition in your function. See the code below:
Regular expression matching of the contents of text files in a directory
I have a directory of text files. I need to set a status for each file based on whether it matches 1, both or neither regex patterns. My plan is: Walk directory If the file’s content: does not match either pattern, status = 1 matches pattern1 BUT NOT pattern2, status = 2 matches pattern2 BUT NOT pattern…
Problem: While loop won’t re-run the program properly
Result: Currently, my program will print a score depending on what the user enters. After the first input, ‘fazli’ the score was 17. My while loop is supposed to keep running until the user enters nothing. The problem is my while loop I believe. It won’t make a new score, it only copies the …
Unique keywords on the column
I’m new to pandas and I have a question. I have a dataframe like and I should remove duplicates on “Keywords” column, no matter if the duplicates are on the same row or on 3 different rows. No matter if it is written “warehouse” or “Warehouse” Everything value duplica…
Python: Save variables-names and use them later in a loop
I downloaded DataFrames (depending on how many assets are in the variable “assets”) and created for each one its own variable by using globals(). Now, I require a loop to pick up each created variable, to perform other tasks with these variables. Before this, I need to “save” the creat…