Reputation: 2253
I have df
num city inc pop
1,0 Абан 29343,00 8683,00
2,0 Агинское 25896,00 17496,00
3,0 Александровский Шлюз 21785,00 15063,00
4,0 Анапа 20000,00 70453,00
5,0 Апатиты 44057,00 57398,00
6,0 Арзамас 24000,00 104831,00
I need to print str, if inc
less than User is typed.
import pandas as pd
df = pd.read_excel("01.xlsx")
price_flat = df['inc']
price_people = raw_input("Enter the summ, that you can pay at month: ")
for str in df:
if price_people <= price_flat:
print str
And print that str, where np
in df differ from np
that user typed on 10000.
For example, if I typed 30000 I should get all str where np
from 20000 to 40000
Upvotes: 0
Views: 81
Reputation: 3497
If I understand correctly, you want to print the data frame only in the range: price_people ± 10000.
price_people = 30000
print( df[ ( df['inc'] >= price_people - 10000 ) & ( df['inc'] <= price_people + 10000 ) ] )
prints out:
num city inc pop
0 1.0 A 29343.0 8683.0
1 2.0 B 25896.0 17496.0
2 3.0 C 21785.0 15063.0
3 4.0 D 20000.0 70453.0
5 6.0 F 24000.0 104831.0
Upvotes: 1