0

I am importing data from excel using Pandas and it looks like below,

    time    Column1     Column2     Column3     ID
0   1.0     181.359     -1.207        9.734     10
1   2.0     181.357     -1.179        9.729     10
2   3.0     181.357     -0.713        9.732     10
3   602.0   179.148     505.520       17.774    1810
4   603.0   179.153     506.824       17.765    1810
5   604.0   179.128     506.169       17.773    1810
6   605.0   179.129     504.141       17.776    1810
7   606.0   179.165     505.214       17.774    1810
8   3003.0  180.032     278.810       17.748    2010
9   3004.0  180.025     279.382       17.749    2010
10  16955.0 450.377     7.271         17.710    4510
11  16956.0 450.375     6.806         17.720    4510
12  16957.0 450.368     7.428         17.710    4510
13  16958.0 450.372     7.892         17.723    4510
14  16959.0 450.359     8.085         17.714    4510

I want to pick up values from the Column1, 2 & 3 based on certain value of ID. For example, if I give ID=1810 I should get values from Column1, 2 & 3 corresponding to 1810 (row 3 to 7). I am using numpy.where function to get the correct row number

a = np.where(data['ID'] == 1810)

but could not find out how to select Column data based on that. Thank you in advance for help!

M Mokashi
  • 3
  • 2

1 Answers1

0

Use pandas.DataFrame.loc: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.loc.html

df.loc[df['ID'] == 1810][['Column1', 'Column2', 'Column3']]