python pandas remove duplicate columns

Here’s a one line solution to remove columns based on duplicate column names: How it works: Suppose the columns of the data frame are [‘alpha’,’beta’,’alpha’] df.columns.duplicated() returns a boolean array: a True or False for each column. If it is False then the column name is unique up to that point, if it is True then the column name is duplicated earlier. For example, using the …

Read more

pandas groupby sort within groups

What you want to do is actually again a groupby (on the result of the first groupby): sort and take the first three elements per group. Starting from the result of the first groupby: We group by the first level of the index: Then we want to sort (‘order’) each group and take the first …

Read more

Importing Pandas gives error AttributeError: module ‘pandas’ has no attribute ‘core’ in iPython Notebook

Apparently the error I got when trying to import pandas for the first time was ValueError: unknown locale: UTF-8 Trying to import again afterwards, gave another error as described in my question above. I found the solution to solve the ValueError on IPython Notebook locale error After updating my bash profile, the error AttributeError: module ‘pandas’ has no attribute ‘core’ did …

Read more

Unknown format code ‘f’ for object of type ‘str’- Folium

The f format code in “{:.0f}”.format(Number) for the Python string formatter requires a floating number, and yet you’re passing to it the variable Number, which is derived from dsa[‘Number’], a string value from the dataframe. You should convert Number to a floating number before passing it to the formatter with “{:.0f}”.format(float(Number)) instead.