-
Notifications
You must be signed in to change notification settings - Fork 0
/
sorting_csv.py
67 lines (39 loc) · 1.68 KB
/
sorting_csv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import pandas as pd
import random
cars = pd.read_csv('Cars.csv', index_col=0)
pd.set_option('max_colwidth', 500)
#input_region = input('Введіть регіон: ')
#input_price = input('Введіть ціну: ')
#input_transmition = input('Введіть трансмісію: ')
#print(cars)
#print(cars['price_usd'].dtype)
#print(cars.groupby('region').region.count())
def create_region_csv(region):
def input_region(cars, region):
cars = pd.read_csv('Cars.csv', index_col=0)
cars_by_region = cars.loc[cars['region'] == region]
return cars_by_region
def create_csv(region = input_region(cars, region)):
region.to_csv('Cars_by_region.csv')
def input_things(input_region):
return input_region, input_price, input_transmition
input_region, input_price, input_transmition = input_things()
def replaced_price(input_price):
input_price = input_price.rsplit('-')
price = []
for item in input_price:
price.append(int(item.strip()))
return price
price = replaced_price(input_price)
def sort_cars(cars, region, price, transmition):
user_cars = cars.loc[(cars['region'] == region) & (cars['price_usd'] >= price[0]) & (cars['price_usd'] <= price[-1]) & (cars['transmition'] == transmition)]
return user_cars
user_cars = sort_cars(cars, input_region, price, input_transmition)
def convert_csv(cars):
cars.to_csv('user_cars.csv')
while user_cars.empty == True:
input_things()
user_cars = sort_cars(cars, input_region, price, input_transmition)
else:
convert_csv(user_cars)
user_cars = pd.read_csv('user_cars.csv')