I wish to create a new list which contains column names of those columns which have atleast one of the following values. Most of the time Quite Often Less than often Never Sample : df ={‘A’:[‘name1’, ‘name2’, ‘name3’, ‘name4’], h_ls = [‘B’…
Tag: pandas
Problem with counting times a parameter is in a certain range
I am trying to count how many times a value, “i”, is in the range i<0.5. I am counting from a csv file. To be clear, I only want the number of times to be appended to a dictionary. I will post my code and the result I get. the result I want is like this:(86 is a place holder,
Group By – Total Hours and Hours by Category in Python / Pandas
I need to calculate Total Hours and Hours by Status per Week using Python / Pandas GROUP BY. I can get Total Hours by each Week: But I don’t know how to also group by Status, so it will be 2 additional columns (On Status Hours and Off Status Hours) If I add Status column just to the groupby part,
Processing multiple modes in pandas
I’m obviously dealing with slightly more complex and realistic data, but to showcase my trouble, let’s assume we have these data: I want to find modal values of purchases by date: agg_mode will show that for user_id 100 we have two modal values: [cookies, jam]. This is totally fine with me, when i…
pandas shift on condition of a column isnull but it removes the first two columns
I have this problem with shifting an entire row based on a column condition if it is NaN. if column 10 is NaN, shift the entire row 3 cells to the right. initial dataframe: I come up with this solution, but the first two columns are gone somehow. df1_copy[df1_copy[10].isnull()] = df1_copy[df1_copy[10].isnull(…
How to delete a certain value in a cell in columns of csv using pandas
I need help with deleting “None” along with extra comma in language columns that have one or more language Here is the existing csv: Where f now looks like: And the result should be like this: There are also other columns that have only ‘None’ values in language column, so I can’…
Shifting depending on different columns and begining the shift depending on changes in columns
I have a dataframe (here an example) Date UnitId ServiceDomineId Interval ServiceTime 01/01/2021 1 1 8:00 30 01/01/2021 1 1 8:30 20 01/01/2021 1 1 9:00 10 01/01/2021 2 1 8:00 50 01/01/2021 2 1 9:00 10 01/01/2021 1 2 8:30 25 01/01/2021 1 2 9:00 15 01/01/2021 1 2 9:30 30 01/01/2021 2 2 8:00 45 01/01/2021 2 2
Python pandas group non repeating values
Hi I have a data frame which looks like this I would like to groupby and sum for non repeating values in col1 for e.g. Is there any way I can do this via pandas functions? Answer IIUC, you could create groups using groupby + cumcount (where the nth occurrences of each col1 value will be grouped the same); the…
How to add a new column rank on based on increasing value of other column in Pandas
I have this dataframe with which i am trying to create a new column rank on basis of increasing values of column Opportunity with pandas required output — Answer You can use rank function:
Copy and split row by if cell condition it met – Pandas Python
I am trying to overcome the issue when I have a cell with specific char(‘;’) which I would like to copy the same line with the amount if splitters that specific cell in specific col got. For example: Index Name Age Car 1 David 45 Honda;Subaru 2 Oshir 32 BMW The result that I am trying to get is th…