'pandas read excel same columns merge

excel = pandas.read_excel(file, ...)
columns = df.columns
print(columns)

["AA", "AA.1", "AA.2"]

this is same names

how do you names merge?

i want ["AA"]



Solution 1:[1]

You say merge, do you want sum? Use groupby with axis=1 and use string manipulation on columns names:

df.groupby(df.columns.str.split('.').str[0], axis=1).sum()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Scott Boston