Python Pandas equivalent in JavaScript

前端 未结 9 1120
时光取名叫无心
时光取名叫无心 2021-01-29 17:24

With this CSV example:

   Source,col1,col2,col3
   foo,1,2,3
   bar,3,4,5

The standard method I use Pandas is this:

  1. Parse CSV<

9条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-29 18:08

    Below is Python numpy and pandas

    ```

    import numpy as np
    import pandas as pd
    
    data_frame = pd.DataFrame(np.random.randn(5, 4), ['A', 'B', 'C', 'D', 'E'], [1, 2, 3, 4])
    
    data_frame[5] = np.random.randint(1, 50, 5)
    
    print(data_frame.loc[['C', 'D'], [2, 3]])
    
    # axis 1 = Y | 0 = X
    data_frame.drop(5, axis=1, inplace=True)
    
    print(data_frame)
    

    ```

    The same can be achieved in JavaScript* [numjs works only with Node.js] But D3.js has much advanced Data file set options. Both numjs and Pandas-js still in works..

    import np from 'numjs';
    import { DataFrame } from 'pandas-js';
    
    const df = new DataFrame(np.random.randn(5, 4), ['A', 'B', 'C', 'D', 'E'], [1, 2, 3, 4])
    
    // df
    /*
    
              1         2         3         4
    A  0.023126  1.078130 -0.521409 -1.480726
    B  0.920194 -0.201019  0.028180  0.558041
    C -0.650564 -0.505693 -0.533010  0.441858
    D -0.973549  0.095626 -1.302843  1.109872
    E -0.989123 -1.382969 -1.682573 -0.637132
    
    */

提交回复
热议问题