def RPK(raw_counts, seq_lengths, seq_in_kb=False):
    """
    Reads Per Kilobase normalization.

    Args:
        raw_counts (pandas.DataFrame): raw RNAseq counts where rows are genes
            and columns are conditions
        seq_lengths (pandas.Series): sequences DNA lengths
        seq_in_kb (bool): True if lengths in kb, False otherwise

    Returns:
        pandas.DataFrame: Normalized counts

    Examples:
        >>> import numpy as np
        >>> np.random.seed(0)
        >>> import pandas as pd
        >>> nb_genes = 1000
        >>> nb_conditions = 5
        >>> raw_counts = np.random.randint(0,1e6,(nb_genes,nb_conditions))
        >>> raw_counts = pd.DataFrame(raw_counts)
        >>> seq_lengths = np.random.randint(100,20000,nb_genes)
        >>> seq_lengths = pd.Series(seq_lengths)
        >>> rpk = RPK(raw_counts, seq_lengths)
        >>> rpk.head()
                       0              1              2              3              4
        0  321202.997719   99612.577387  142010.101010   38433.365917  313911.697621
        1   26853.843441  155566.114245   63431.417489   53620.768688   21611.248237
        2   97195.319962   71353.390640   59624.960204  117133.237822  117212.034384
        3  132006.796941   72465.590484  356436.703483  256785.896347  229981.733220
        4   48384.227419   34354.424576   18889.143614   37956.492944   45220.490091

    """
    seq_lengths = seq_lengths[raw_counts.index]
    seq_lengths = seq_lengths.fillna(seq_lengths.mean())
    if not seq_in_kb:
        seq_lengths_in_kb = seq_lengths / 1000.0
    else:
        seq_lengths_in_kb = seq_lengths
    rpk = (raw_counts.T / seq_lengths_in_kb).T
    return rpk
