Renaming column names in Pandas

How do I change the column labels of a pandas DataFrame from: [‘$a’, ‘$b’, ‘$c’, ‘$d’, ‘$e’] to [‘a’, ‘b’, ‘c’, ‘d’, ‘e’]. 3 32 RENAME SPECIFIC COLUMNS Use the df.rename() function and refer the columns to be renamed. Not all the columns have to be renamed: df = df.rename(columns={‘oldName1’: ‘newName1’, ‘oldName2’: ‘newName2’}) # Or … Read more

Difference between String replace() and replaceAll()

In java.lang.String, the replace method either takes a pair of char’s or a pair of CharSequence‘s (of which String is a subclass, so it’ll happily take a pair of String’s). The replace method will replace all occurrences of a char or CharSequence. On the other hand, the first String arguments of replaceFirst and replaceAll are regular expressions (regex). Using the wrong function can lead to subtle bugs.

Replace a character at a specific index in a string?

String are immutable in Java. You can’t change them. You need to create a new string with the character replaced. String myName = “domanokz”; String newName = myName.substring(0,4)+’x’+myName.substring(5); Or you can use a StringBuilder: StringBuilder myName = new StringBuilder(“domanokz”); myName.setCharAt(4, ‘x’); System.out.println(myName);