Having issue with the code, I’m getting error with this code, was trying to make script to take a backup of a file scheduled Answer dest_file_name is a global variable, as it is defined at the top-level of a script. When you assign a new value to a global variable within a function, you have to declare …
Tag: python
discord bot sends infinite messages regardless of user input
I’m trying to make a discord bot respond when someone makes laughing remarks but it infinitely sends gifs whenever someone types anything code is as follows Answer In addition to some formatting, I changed some of the variables for the API calls. I commented out the keep_alive.py as I assume you are usi…
Create pandas dataframe on column name conditions
Python newbie attempting a complex pandas dataframe logic I have multiple dataframes I need to join but I’ll show two below for the example. The dataframe have duplicate columns labelled with suffix ‘_duplicate’. I need to replicate the row instead of having the duplicate column as seen belo…
Python: Building list of lists using dictionary recursion
I have a very complicated problem that I am sort of hoping to rubberduck here: I have a dictionary: whose structure wont always be the same (i.e., there could be further nesting or more keys in any sub-dictionary). I need to be able to generate a specifically ordered list of lists (contained sub-lists need no…
Python: Pivot dataframe to introduce new columns
I have the following dataframe I would like to pivot it to get the following: Answer
Convert a list of Vector to a matrix with petsc4py
I have a list of vectors that I want to gather in a single matrix Z. Here is the code I tried to use : I tried setValues and setValuesBlocked. When I run this script on one core, that works well. The result printed is : but in parallel I have issues : I think it’s because PetSc waits for
How to remove the date from time data when it is separated by a space?
I have some data in a current .csv file that is space separated then ; separated. I get how to do the sep”;” but the problem is the spaces. It looks a little like this: I need to get the date removed so that in “Time” there is only the variable of time (ie. I don’t need the syste…
Finding specifig value in class – Selenium (Python)
I’m trying to scrap a website using selenium. I tried using XPATH, but the problem is that the rows on the website change over time… How can I scrap the website, so that it gives me the output ‘21,73’ ? Answer You can just use querySelector that accepts CSS selectors. I personally like…
Problem: In dataset i have data of country,state and city. Where some state and city name is 0.so,I want to replace “0” value of state with city name
I tried this method. In this code list some city of israel and generate 500 random value of it. And apply condition to insert data in israel state location where data is 0. Answer
Why can’t I install a Python package with the Python requirement “>=3.8,<3.11" into a Poetry project with the Python version "^3.9"?
I’m having an issue installing dependencies into my Poetry project. If I run poetry new (as described in https://python-poetry.org/docs/basic-usage/), I can create a new project: My project structure looks like this after I delete a few files not needed for this reproduction: My pyproject.toml file look…