Skip to content

Tag: pandas

How can I make a: for i in range work with a float [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed 1 y…

Aggregate data with two conditions

I have a data frame that looks something like this: What I would like to do is aggregate the data if the dates are the same – but only if the name is different. So the above data frame should actually become: Currently I am almost doing it with: However, this will also aggregate the ones where the name …

Python pandas replace based on partial match with list item

I have a large three-column dataframe of this form: And a long list with entries like this: I want to replace the entries in the Shaperef column of the df with a value from the list if the full Shaperef string matches any part of any list item. If there is no match, the entry is not changed. Desired output:

Using groupby and querying that group

I have a dataframe that I would like to group by one column (dadate) and then query another column (Place) to count only those with the value 1. The above is what I have tired with the error “‘DataFrameGroupBy’ object has no attribute ‘query’” Answer Create the Boolean Series the…

Python Rank with non numeric columns

I’m trying to find a way to do nested ranking (row number) in python that is equivalent to the following in TSQL: I have a table thank looks like this: Looking for Python equivalent to: The output to be: I’ve tried to use rank() and groupby() but I keep running into a problem of No numeric types t…

reduce() to merge if there are blank DataFrame

I want to use reduce() function to merge data. However, sometimes some dataframe df1 to df8 might be blank (but there is at least one dataframe not be blank). And I do not want to detect which one. For example, this time df1 to df7 are blank and only df8 is non-blank. Next time df1, df2, df5 are non-blank. Ho…

Create and fill a DataFrame column based on conditions

I have a DataFrame and I need to create a new column and fill the values acording to how many words in a list of words are found in a text. I’m trying de code below: This code actually create a new column, but fill all the rows with the last ‘count_found_words’ of the loop. is there a right …