I have dataframe which should be filled by understanding rows understanding like we do in excel. If its continious integer it fill by next number itself. Is there any function in python like this? output required: I tried df.interpolate(method=’krogh’) #it fill 1,2,3,4,5,6 but incorrect others. An…
Tag: pandas
Find median of interval data in python
I am exploring different python libraries and I wondering how to find approximate median value of the grouped data set. Here is a table for a reference. Age frequency 1-10 123 10-20 350 20-30 200 30-40 1700 40-50 360 50-60 60 Is there any function or do I need to hard code the formula and then have a loop goi…
Apply a softmax function on groupby in the same pandas dataframe
I have been looking to apply the following softmax function from https://machinelearningmastery.com/softmax-activation-function-with-python/ I am trying to apply this to a dataframe which is split by groups, and return the probabilites row by row for a group. My dataframe is: In this instance there are two di…
add a suffix when col names are similar
I am merging two dataframes and both of them have a col called “man”. After the join, one col is called “man_x” and the second is called “man_y”. Is it possible to append the table name or any other string instead of x, y when column names are the same? After this, If I add…
Convert a pandas df to defaultdict and look for matching positive and negative numbers
I have a dataframe like this: What i want to do know i convert the df into a defaultdict and look for only the matching matching positive and negative numbers per id so i want my desired dict to look something like this: I try to do this below but i get this error: Any idea how to solve this
Multiple boxplots based on conditions
I have a dataframe with two columns. The power column represents the power consumption of the system. And the component_status column divide the data in two, based when the component is OFF or ON. When the values are 153 is when the component is ON and when the values are 150 the component is OFF. The result …
Python Pandas compare two dataframe and keep only data that index appears in both dataframe
I have two dataframe, and would like to keep only row that both matches exactly on index (in this case datetime), and would like to return as two separate dataframe accordingly. Desired output: Answer Use align with inner join: *Note this will align both index and columns (which works for the provided sample)…
Panda iterating through CSV matching index out-of-bounds
I’m running into an issue with my locate / match statement. I’m trying to match the column “IP” assign it as the index and iterate through a csv of a few thousand hosts. Whenever the below script makes its way back up to process the second ‘IP’ I fail with a “single p…
Is overlay how=’difference’ supposed to operate differently from geopandas 0.9 vs 0.10?
I was using the difference set operation for a different problem, but I would get an empty geodataframe or None type when replacing a polygon with the difference in my geodataframe. I found it to be a result of having non-intersecting polygons and doing the difference set-operation. I was wondering is this no…
Python Data Frame summary
I have dataframe (df table below): Every user can post in any category. I have to calculate HOW MANY DISTINCT USERS has a post in category A and at the same time has posts in categories, B, C and D. Table like: User Category 1 A 1 B 33 B 33 C 33 D 54 A 54 B 87 A