Pandas apply function to values in a DataFrame

Apply your function to all values in a dataframe:

df = df+1
df = df.apply(np.sqrt)
df = df.apply(lambda x: np.log2(x+1))
df = df.apply(lambda x: function(x))

Apply function to a column or a row of the dataframe:

df.loc[:,'yourLabel'] = df.loc[:,'yourLabel'].map(lambda x: function(x))
df.loc['yourLabel',:] = df.loc['yourLabel',:].map(lambda x: function(x))

df.loc[:,'yourLabel'] = df.loc[:,'yourLabel'].apply(lambda x: function(x))
df.loc['yourLabel',:] = df.loc['yourLabel',:].apply(lambda x: function(x))

Source:
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.apply.html;
https://stackoverflow.com/questions/34962104/pandas-how-can-i-use-the-apply-function-for-a-single-column

Substitute ‘\r’ in Excel output to ‘\n’ for Unix

When outputing tsv from Excel directly, it added an unpleasant ‘\r’ at the end of each line. And you won’t even notive it by opening the file in TextWrangler. It can be checked by head -n 2 input.txt, you will see the difference.

Here is how to replace the ‘\r’ with ‘\n’:

cat input.txt | tr '\r' '\n' > output.txt
cat input.txt | tr '^M' '\n' > output.txt

While typing ^M in the command, do not use shift+6 & M. You should use ctrl+v+m

Source: https://github.com/bioinfocore/bashCore