Skip to content

Tag: pandas

Getting max values based on sliced column

Let’s consider this Dataframe: I want to compute column D based on: The max value between: integer 0 A slice of column B at that row’s index So I have created a column C (all zeroes) in my dataframe in order use DataFrame.max(axis=1). However, short of using apply or looping over the DataFrame, I …

df.drop does not work properly, pandas python

I have this excel file that I would like to “normalize” with the below code by dropping the A and B columns and then dropping the Rows 1,2,3,5 and making the row 4 as header. But I keep getting this weird df that I dont understand the reason why Also: Answer You must explicitely set the column nam…

How to “describe” a column in pandas for python

I’m using pandas in python and I have a dataframe where one column is a timestamp and others contain data. The blue line stays constant for a while, then suddenly increases to zero, then at some point descends again to about -98 and stays there until it suddenly goes up to zero. What I need is a new col…

to_json without header and index pandas

I have the following pandas DF How can I convert this DF to json to be like: My best try was: But I got this output: Bonus Doubt: Is it possible to parse only the values 1,2,3 and 4 of column data to int? Answer The first approach is to squeeze your dataframe before use to_json For the bonus, use