Let’s take an example. I have a list of categories that are identified : The strings in that list can’t be a substring of another string in that list. And a dataframe : I would like to add a column Category to this dataframe. If the string in the column Items starts as a string in L_known_categories, no matter the
Tag: dataframe
How to extract all uppercase row to a new data frame
I have a pandas data frame which looks like this Name Index1 Index2 AAA 67 70 Aaa 55 80 Abb 32 20 BBB 84 45 Baa 80 70 Bbb 13 40 where some rows have names with all uppercase and some with lowercase. How can i create another dataframe with only the uppercase rows expected output will be : Name
Mutiple style for one DataFrame issues
I would like to understand how “style” works in python, I always have the same error : AttributeError: ‘Styler’ object has no attribute …. for now, I manage to have : the first row in yellow but not the conditional formatting (df_x0) and the conditional formatting blue and orange cells but the first row disappear because I am obligate to
Grouping of a dataframe monthly after calculating the highest daily values
I’ve got a dataframe with two columns one is datetime dataframe consisting of dates, and another one consists of quantity. It looks like something like this, I want to make another dataframe. It should consist of two columns one is Month/Year and the other is Till Highest. I basically want to calculate the highest quantity value until that month and
Convert List of tuples to dataframe
Having a data as below: I need to convert this data to data frame. I need the dataframe/output as follows: COL1 COL2 COL3 COL4 10 L5 [‘abc’] 0 15 L6 [‘bda’, ‘LAS’] 5 Answer You could use tuple unpacking in a comprehension:
comparing two pandas columns particular content and changing the color as per condition
I have a data frame as shown below. In the first row I need to compare SPEC_TYP with max. In the 2nd row I need to compare SPEC_MAX with max.In the 3rd row SPEC_TYP with max and in some other cases I need to compare SPEC_MIN with min ,SPEC_MAX with max and so on. I searched in SO and google
Pandas DataFrame and grouping Pandas Series data into individual columns by value
I am hoping someone can help me optimize the following Python/Pandas code. My code works, but I know there must be a cleaner and faster way to perform the operation under consideration. I am looking for an optimized strategy because my use case will involve 16 unique ADC Types, as opposed to 4 in the example below. Also, my initial
Sort DataFrame based on part of its index
What I would like to achieve I have a DataFrame whose indices are “ID (int) + underscore (_) + name (str)”. I would like to sort the data based on the ID. What I tested I tried to use sort_index and failed. https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.sort_index.html To be honest, I’m stuck at the debug of lambda. Environment Python 3.10.5 Pandas 1.4.3 Answer Try
Transform dataframe format
How do I convert the following dataframe from df1 to df2? Thanks in advance! Answer You could try as follows. Apply .str.split to columns a and b in a loop, each time exploding the result. This will get us 2 pd.Series and we use pd.concat to put them together. After this, we just need to assign col c, and reset
sort values and create new column based on result
I have this example which produce this dataframe i want to sort values from column A and B and C from higher to lower and put result column headers in new column D like this: I hope it’s clear, thank you Answer You can try: