Extracting specific columns in numpy array

前端 未结 9 1127
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 02:27

This is an easy question but say I have an MxN matrix. All I want to do is extract specific columns and store them in another numpy array but I get invalid syntax errors. He

相关标签:
9条回答
  • 2020-11-28 02:47

    You can use the following:

    extracted_data = data.ix[:,['Column1','Column2']]
    
    0 讨论(0)
  • 2020-11-28 02:47

    you can also use extractedData=data([:,1],[:,9])

    0 讨论(0)
  • 2020-11-28 02:58

    I think the solution here is not working with an update of the python version anymore, one way to do it with a new python function for it is:

    extracted_data = data[['Column Name1','Column Name2']].to_numpy()
    

    which gives you the desired outcome.

    The documentation you can find here: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_numpy.html#pandas.DataFrame.to_numpy

    0 讨论(0)
提交回复
热议问题