Reputation: 827
I have imported the data in csv format in pandas. Can anybody tell me how i can find the values above 280 in one of the columns that i have and put them into another data frame. I have done the below code so far:
import numpy as np
import pandas as pd
df = pd.read_csv('...csv')
And the part of data is like the attached pic:enter image description here
Upvotes: 4
Views: 20897
Reputation: 863501
You need boolean indexing
:
df1 = df[df[2] > 280]
If need select also only column add loc
:
s = df.loc[df[2] > 280, 2]
Sample:
df = pd.DataFrame({0:[1,2,3],
1:[4,5,6],
2:[107,800,300],
3:[1,3,5]})
print (df)
0 1 2 3
0 1 4 107 1
1 2 5 800 3
2 3 6 300 5
df1 = df[df[2] > 280]
print (df1)
0 1 2 3
1 2 5 800 3
2 3 6 300 5
s = df.loc[df[2] > 280, 2]
print (s)
1 800
2 300
Name: 2, dtype: int64
#one column df
df2 = df.loc[df[2] > 280, [2]]
print (df2)
2
1 800
2 300
Upvotes: 5