I've checked the other questions related to this issue but none of the solutions worked (Changing column names of a data frame, Renaming column names in Pandas)
I have a data frame where I use indexes to merge data frames together. That works fine, except the new column headers on the data frame likes to double the name in the new column. For example: I expect the new column in the main data frame to say "LiveDemand" but instead it says "LiveDemand$LiveDemand".
I then try to use colnames() to replace the column header to a new name. I get no errors, but when I check the data frame the name is unchanged. Can anyone help explain why? Here is my code:
mainDF$LiveDemand <- DemandDF[DemandIndexes, "LiveDemand"]
#Result is a new column called 'LiveDemand$LiveDemand'
colnames(mainDF)[which(names(mainDF) == "LiveDemand$LiveDemand")] <- "LiveDemand"
#I've also tried
colnames(mainDF)[18] <- "LiveDemand"
#This as well
mainDF<- rename(mainDF, LiveDemand= "LiveDemand")
All three methods give no errors, but the column header doesn't change (none of them do). What is really strange is when I use rename, if I say the old column name is "LiveDemand$LiveDemand" it gives me an error saying it doesn't exist, but when I go to view the data frame, it clearly says "LiveDemand$LiveDemand". Any ideas?