Skip to content

Tag: pandas

How to add column name for index in Pandas dataframe

This is about Pandas dataframe. I have a dataframe made by following python code. There is no column name for index. What I’d like to do is adding index’s name like ‘date’ in attached capture. I did following, but error occurred because there is no such name of column in df_test. I kno…

pandas sorting by subtotal

I have a multi indexed dataframe like below. I’ m giving the full data consciously, because when I try this solution pandas multi index sort with several conditions with small data it is OK, but when I try with full data, it doesn’t work. Multi-indexes are: ‘MATERIALNAME’ and ‘CU…

Pandas dataframe slice left assignment

I want to do a left assignment of one column’s values between DataFrame slices where the indexes don’t match. Is there a single expression that will work whether the left slice’s indexes are a subset or a superset of the right slice’s? The following attempt fails when left is a subset:…

Pandas count number of rows since value > current cell

I have a Dataframe df: I would like to count the number of rows backwards until a value greater than the current value is found, or until the first row is reached. For example, the result would be: I am basically trying to find the value of n in df[‘col_1’].rolling(n).max() for each value of the s…