I have a data frame with the following columns: First, I want to check that all 32835 values in the “zip_code” column match to a “part_no” with the following pattern, 01xxxxxx, where the Xs are numbers. Then, I want to make sure all 01xxxxxx part_no correspond to a 32835 “zip_cod…
Tag: pandas
Getting Rolling Sum per Group
I have a dataframe like this: I would like to get the Sum of the last three months (excluding the current month), per Product_ID. Therefore I tried this: My code is failing, because it does not only calculate it per product, but it will give me also numbers for other products (let’s say Product 2, quart…
Visualize each row of pandas data frame as a tree
I have a data frame having 4 columns A, B, C, D. I need to visualize/ print each row of my data frame as a tree structure. Example: df[‘A’] = franchisee df[‘B’] = sign off df[‘C’] = status df[‘D’] = registration Then, I need to visualize this row as a tree where…
XLWINGS conditional formatting based on value
I have a dataframe in Pandas that I have exported to Excel and formatted headers etc. using XLWINGS. That works like a charm. But I would like to format two columns based on their value in each cell (row), so if the value is above 0 then green and below zero then red. I can’t seem to find that option
How to import API data using Pandas?
I am trying to pull some data from EIA API, below is what I tried but I’m getting the error on the first line of code: AttributeError: ‘str’ object has no attribute ‘text’ Any help would be much appreciated! Answer You haven’t requested anything from the API. Look carefully…
Pandas select rows from a DataFrame based on column values?
I have below json string loaded to dataframe. Now I want to filter the record based on ossId. The condition I have is giving the error message. what is the correct way to filter by ossId? Answer I think your issue is due to the json structure. You are actually loading into df a single row that is the whole
Pandas how to count when string values converted to_numeric is greater than N?
I have monthly dataframe (df) that is already in min – max ranges like the below: I want to know the number of times the max wind speed was below the calib number each month. So I am trying to create a column Speed below calib (sbc) like below. The above code is not working and I am getting the
Pandas: Create table from data frame matching columns to a list
I am trying to create a matrix from a data frame and a list. The list and column 1 of the data frame contain the same strings, however, not all of the strings in the list are in the column 1 and are not in the same order (see example below). I would like to search through the data frame,
Pandas groupby – Find mean of first 10 items
I have 30 items in each group. To find mean of entire items, I use this code. That returns a value like this. However, I would like to find the mean of the first 10 items in the group instead of the entire items. That code return only a single Value instead of a pandas series. So I’m getting errors
How to do line level logic in Pandas
I have a table that has a bunch of columns and I need to create a new column based on the row type but the logic will be different for each type of row. My data looks like this: type field1 field2 field3 field4 1 a b c 17 2 e f g 20 3 i j k 100 the