Skip to content

Pandas_Numpy

vanhoan310 edited this page Dec 28, 2019 · 7 revisions
  1. Read file with index column from data https://stackoverflow.com/questions/36606931/how-to-set-in-pandas-the-first-column-and-row-as-index

  2. Take rows/columns based on some criteria https://stackoverflow.com/questions/17071871/select-rows-from-a-dataframe-based-on-values-in-a-column-in-pandas

  3. Create a pandas array with row and column names
    expression_matrix_pd = pd.DataFrame(expression_matrix_np, columns = ['a','b']//expression_matrix.columns, index = ['1','2']//expression_matrix.index)

  4. Different indices Numpy vs Pandas
    x = np.array[[1,2,3],[4,5,6]]
    x[[0,1],[0,1]] => [1, 5]
    y = pd.DataFrame(x, ['1', '2'], ['A', 'B', 'C'])
    y.loc[['1', '2'], ['A', 'B']] => 2x2 matrix.

  5. Conditional selection df = pd.DataFrame

  6. Numpy sort rows/columns https://gist.github.com/stevenvo/e3dad127598842459b68

  7. Concat empty array https://stackoverflow.com/questions/22732589/concatenating-empty-array-in-numpy/22732845

Clone this wiki locally