I want to replace nan values in B with A in df: df: df data types: I tried: and it caught error: Answer Use numpy.where for avoid floats in output column: If need strings in output:
Combining unique elements of a DataFrame in a list
I’ll try to ask my question as clearly as possible. I have the following DataFrame which looks like this Now I want to keep values unique to each player only once. Ideally in a list, but that’s not a big deal. For example, player A and B play soccer so I don’t want soccer in the output. tenn…
Create new pd dataframe column that gives a date based on day and week starting data
I have a pandas dataframe that has two columns, the first column is ‘Week Starting’ and the other is ‘Day’. I wanna create a new column that uses the data from the other two columns to give a full date. For example, from the table below, the first entry of the new column should be 5/04…
how to slice pandas dataframe columns with default values instead of error
I have a following set of dataframes I am trying to slice them so that I only have [‘col1’, ‘col3’, ‘col4’] While I’m able to achieve that using slicing df[[‘col1′,’col3’, ‘col4’]], in the case that col4 doesn’t exist , it giv…
Bot will not log an automod event if user has blocked the bot
If someone says a bad word that triggers the automod, the bot will delete the message, DM the user, and log it in a log channel. The problem is if someone blocks the bot and says a bad word, the bot can’t DM the user which doesn’t allow the bot to log the event in a log channel. I tried
In Pandas, how do I convert a number column to discrete values quickly?
I have a dataframe with an Integer column, which I need to convert to discrete value bands, I am currently doing this using apply with my own function, as seen bellow, however this is rather slow, is there any way to quickly do this? Caller function here: My data look like this: Answer IIUC and given the mix …
Mixing horizontal and vertical ticks
I have the example plot shown below. How can I make the first and third x-axis tick horizontal and the second and fourth tick vertical? Answer Not sure if there is an automate way of doing it, but you can do it “manually” for each tick: Every item of the ticks_labels list is a Text artist, so you …
Convert a normal python code to an MPI code
I have this code that I would like to edit and run it as an MPI code. The array in the code mass_array1 is a multi-dimensional array with total ‘iterations’ i*j around 80 million. I mean if I flatten the array into 1 dimensional array, there are 80 million elements. The code takes almost 2 days to…
Concurrency for requests
I have a python script and I’m sending post requests to same url with different data(different ids). I have to send requests for each id and check them continuously to see if there is a change. I’m handling it with iterating an “ids” list with for loop and sending request for each id a…
Cant wrap my head around Classes and Kivy
I am trying to use kivy.clock object more specifically Clock.schedule_interval to take temperature readings every couple seconds. I create a method in my main screen class (MyTerrLayout(Screen)) called clockAction. now when I type in Clock.schedule_interval(clockAction, 2) I get: So I tired to do self.clockAc…