Given the following DataFrame of pandas in Python: Displays the switching on and off of 3 light bulbs at different times using date and time objects. I want to add a new column, called cost_days. This column will include only for rows where the variable using_time is different from NaT. Information on how man…
Tag: pandas
I want to add date range where value is True in pandas
Dt 1/2/21 2/2/21 3/2/21 4/2/21 5/2/21 6/2/21 7/2/21 Attendance(Expected output in python) san TRUE TRUE TRUE TRUE TRUE TRUE TRUE 1/2/21 – 7/2/21 don TRUE TRUE FALSE TRUE TRUE TRUE TRUE 1/2/21 -2/2/21,4/2/21-7/2/21 sam FALSE TRUE TRUE FALSE TRUE TRUE TRUE 2/2/21 – 3/2/21,5/2/21-7/2/21 den FALSE FAL…
Find average value of number before word in a list of sentences
I am trying to find the average value of numbers before certain words. I have a list of sentences: [‘I had to wait 30 minutes’, ‘It took too long had to wait 35 minutes’, …] I want to find the average value of the numbers before a certain word which in this case is minutes. So th…
How to create a one-hot-encoding for the intermediate class?
Let’s say I have 3 classes: 0, 1, 2 One-hot-encoding an array of labels can be done via pandas as follows: What I’m interested in, is how to get an encoding that can handle an intermediate class, e.g. class in the middle between 2 classes. For example: for class 0.4, resulting encoding should be […
How to create multiple lists with the sum of different columns?
I have a large data set of machine speeds per simulation. I have a column or which simulation it is as well as columns for the different machines. Now I would like to have different lists of the sum of each machine per simulation so that I can do analysis on this as well as create plots for it. Here
extract key and values from nested jsons and put in a DataFrame
I have a json object that looks like this: Is it possible to extract all dates (key) along with their respective “revenue” values and put them into a dataframe that looks likethis: Answer How about something like:
extract extreme values from xarray dataarray
I have a rather large dataset, and need to find in that dataset extreme values, including coordinates. The real dataset is much larger, but let’s take this one for testing: I want to find in this dataarray all values larger than 2. I found on here this solution: but even in this small example, this prod…
panda dataframe extracting values
I have a dataframe called “nums” and am trying to find the value of the column “angle” by specifying the values of other columns like this: When I do so, I do not get a singular number and cannot do calculations on them. What am I doing wrong? nums Answer First of all, in general you s…
Convert Spreadsheet to Data Frame Syntax in Python
Out of the box (and broad) question here: I have a spreadsheet that I’d like to use as an example in a question to the SO community, but I have a feeling most SO helpers would not like to deal with spreadsheets as data input/examples. Instead, I’d like to provide an already-transformed data frame …
Dask Df convert All Dtype using dictionary
Is there an easy equivalent way to convert all columns in a dask df(converted from a pandas df) using a dictionary. I have a dictionary as follows: and would like to convert the pandas|dask df dtypes all at once to the suggested dtypes in the dictionary. Answer Not sure if I understand the question correctly,…