![]() ![]() Pandas allows one to index using boolean values whereby it selects only the True values. For example, using the given example, the returned value would be. 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. Suppose the columns of the data frame are ĭf.columns.duplicated() returns a boolean array: a True or False for each column. ![]() Here's a one line solution to remove columns based on duplicate column names: df = df.loc.copy() Any Suggestions would be appreciated.ĭata file (note: in the real file, columns are separated by tabs, here they are separated by 4 spaces): Time Time Relative N2 Time Time Relative H2 Result in uniquely valued index errors: Reindexing only valid with uniquely valued index objects I want: Time, Time Relative, N2, H2Īll my attempts at dropping, deleting, etc such as: df=df.T.drop_duplicates().T The column names are: Time, Time Relative, N2, Time, Time Relative, H2, etc.Īll the Time and Time Relative columns contain the same data. I am reading a text file that has duplicate columns via: import pandas as pd What is the easiest way to remove duplicate columns from a dataframe? ![]()
0 Comments
Leave a Reply. |