Skip to content
Advertisement

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

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:

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

Advertisement