Skip to content

Tag: pandas

Reverse a get_dummies encoding in pandas

Column names are: ID,1,2,3,4,5,6,7,8,9. The col values are either 0 or 1 My dataframe looks like this: I want the column names in front of the ID where the value in a row is 1. The Dataframe i want should look like this: Please help me in this, Thanks in advance Answer set_index + stack, stack will dropna by …

convert dataframe row to dict

I have datarame like the sample data below. I’m trying to convert one row from the dataframe in to a dict like the desired output below. But when I use to_dict I get the indice along with the column value. Does anyone know how to get convert the row to a dict like the desired output? Any tips greatly ap…

Pandas: select cell value using pd.at with condition

I’d like to select specific cell values from a Pandas Dataframe. I want to filter out rows with specific values in column A, and then get the values from column B. From what I understand, the correct way to do this is to use df.at, so I’ve tried but this doesn’t work. I’ve also tried, …

Pandas DataFrame column numerical integration

Currently I have a DataFrame as shown below: I would like to do the numerical integration of Current with TimeSec (∫Idt) for different Devices and collect the data into a new DataFrame as below: The problem is that the time interval is not even and the number of data for each device is not even as well. Answe…