How to find the minimum value of a list element which is based on unique value of the same list using PythonHow do I sort a list of dictionaries by a value of the dictionary?Finding the index of an item given a list containing it in PythonHow do I return multiple values from a function?How to remove an element from a list by index?Getting the last element of a listHow do I get the number of elements in a list?How do I concatenate two lists in Python?How to find if directory exists in PythonGet unique values from a list in python“Large data” work flows using pandas
Most practical knots for hitching a line to an object while keeping the bitter end as tight as possible, without sag?
Potential new partner angry about first collaboration - how to answer email to close up this encounter in a graceful manner
Dealing with an extrovert co-worker
Why in most German places is the church the tallest building?
Is there a known non-euclidean geometry where two concentric circles of different radii can intersect? (as in the novel "The Universe Between")
Why don't electrons take the shorter path in coils?
Start from ones
Singleton Design Pattern implementation in a not traditional way
Can anyone recognise the location and uniforms in these pictures
Was Switzerland really impossible to invade during WW2?
Why is less being run unnecessarily by git?
Justifying the use of directed energy weapons
Shouldn't the "credit score" prevent Americans from going deeper and deeper into personal debt?
Efficiently pathfinding many flocking enemies around obstacles
Does travel insurance for short flight delays exist?
Are modern clipless shoes and pedals that much better than toe clips and straps?
Why don't we use Cavea-B
1980's sci fi book series, subspace is a sponge, young man in emergency suit can propel himself by sucking in the sponge stuff
LeetCode: Pascal's Triangle C#
What is the history of the university asylum law?
What is wrong about this application of Kirchhoffs Current Law?
Did a flight controller ever answer Flight with a no-go?
How do I request a longer than normal leave of absence period for my wedding?
Church Booleans
How to find the minimum value of a list element which is based on unique value of the same list using Python
How do I sort a list of dictionaries by a value of the dictionary?Finding the index of an item given a list containing it in PythonHow do I return multiple values from a function?How to remove an element from a list by index?Getting the last element of a listHow do I get the number of elements in a list?How do I concatenate two lists in Python?How to find if directory exists in PythonGet unique values from a list in python“Large data” work flows using pandas
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a csv like the following
SKU;price;availability;Title;Supplier
SUV500;21,50 €;1;27-03-2019 14:46;supplier1
MZ-76E;5,50 €;1;27-03-2019 14:46;supplier1
SUV500;49,95 €;0;27-03-2019 14:46;supplier2
MZ-76E;71,25 €;0;27-03-2019 14:46;supplier2
SUV500;32,60 €;1;27-03-2019 14:46;supplier3
I am trying to get as an output a csv that will have the following
SKU;price;availability;Title;Supplier
SUV500;21,50 €;1;27-03-2019 14:46;supplier1
MZ-76E;5,50 €;1;27-03-2019 14:46;supplier1
Where for each SKU I want to get only the record in which the price is the minimum
How can I do it because I am totally lost with pandas? with classical if for? with lists?sets?
Any ideas?
python python-3.x
add a comment |
I have a csv like the following
SKU;price;availability;Title;Supplier
SUV500;21,50 €;1;27-03-2019 14:46;supplier1
MZ-76E;5,50 €;1;27-03-2019 14:46;supplier1
SUV500;49,95 €;0;27-03-2019 14:46;supplier2
MZ-76E;71,25 €;0;27-03-2019 14:46;supplier2
SUV500;32,60 €;1;27-03-2019 14:46;supplier3
I am trying to get as an output a csv that will have the following
SKU;price;availability;Title;Supplier
SUV500;21,50 €;1;27-03-2019 14:46;supplier1
MZ-76E;5,50 €;1;27-03-2019 14:46;supplier1
Where for each SKU I want to get only the record in which the price is the minimum
How can I do it because I am totally lost with pandas? with classical if for? with lists?sets?
Any ideas?
python python-3.x
add a comment |
I have a csv like the following
SKU;price;availability;Title;Supplier
SUV500;21,50 €;1;27-03-2019 14:46;supplier1
MZ-76E;5,50 €;1;27-03-2019 14:46;supplier1
SUV500;49,95 €;0;27-03-2019 14:46;supplier2
MZ-76E;71,25 €;0;27-03-2019 14:46;supplier2
SUV500;32,60 €;1;27-03-2019 14:46;supplier3
I am trying to get as an output a csv that will have the following
SKU;price;availability;Title;Supplier
SUV500;21,50 €;1;27-03-2019 14:46;supplier1
MZ-76E;5,50 €;1;27-03-2019 14:46;supplier1
Where for each SKU I want to get only the record in which the price is the minimum
How can I do it because I am totally lost with pandas? with classical if for? with lists?sets?
Any ideas?
python python-3.x
I have a csv like the following
SKU;price;availability;Title;Supplier
SUV500;21,50 €;1;27-03-2019 14:46;supplier1
MZ-76E;5,50 €;1;27-03-2019 14:46;supplier1
SUV500;49,95 €;0;27-03-2019 14:46;supplier2
MZ-76E;71,25 €;0;27-03-2019 14:46;supplier2
SUV500;32,60 €;1;27-03-2019 14:46;supplier3
I am trying to get as an output a csv that will have the following
SKU;price;availability;Title;Supplier
SUV500;21,50 €;1;27-03-2019 14:46;supplier1
MZ-76E;5,50 €;1;27-03-2019 14:46;supplier1
Where for each SKU I want to get only the record in which the price is the minimum
How can I do it because I am totally lost with pandas? with classical if for? with lists?sets?
Any ideas?
python python-3.x
python python-3.x
asked Mar 27 at 16:48
user10358702
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
A non pandas solution, this could get your required output.
EDIT: Added csv writer to solution
EDIT: only accept records with '1' in at row[2]
from collections import defaultdict
import re
from operator import itemgetter
import csv
fin = open('SKU_csv.csv', 'r', encoding="utf8")
csv_reader = csv.reader(fin, delimiter=';')
fout = open('test_out.csv', 'w', newline = '')
csv_writer = csv.writer(fout, delimiter=';')
csv_writer.writerow(next(csv_reader)) # print header
d = defaultdict(list)
for row in csv_reader:
if int(row[2]) != 1:
continue
key = row[0]
val = row[1].replace(',', '.')
price = float(re.search('d+.d+', val).group(0))
d[key].append([row, price])
fin.close()
for arr in d.values():
minimum, _ = min(arr, key=itemgetter(1)) # minimum price (at arr idx 1)
csv_writer.writerow(minimum)
fout.close()
'''
*** test_out.csv contents
SKU;price;availability;Title;Supplier
SUV500;21,50 €;1;27-03-2019 14:46;supplier1
MZ-76E;5,50 €;1;27-03-2019 14:46;supplier1
'''
float(re.search('d+.d+', val).group(0)) is not working with group, and some SKU of products display something like korean?! characters in front
– user10358702
Apr 3 at 20:32
I can't guess why group(0) is not working for you. I worked for me given your sample data. Perhaps you could edit your post to include some of the lines that have those characters. Then get back to me and I'll see if I can help.
– Chris Charley
Apr 3 at 21:37
For the characters I added encoding="utf8" for the writing I think its ok, and for the price I did price = float(val) , what re.search is doing together with group?
– user10358702
Apr 3 at 22:18
@Nikos If its working for you, ok. The regular expressionre.search(...is looking for the digits to convert to a float
– Chris Charley
Apr 3 at 23:51
How can be improved so as to get the minimum based on availability 1?
– user10358702
Apr 11 at 8:08
|
show 1 more comment
In pandas you can do the following
import pandas as pd
df= pd.read_csv('your file')
As andy pointed out below this returns only the price and SKU columns
df_reduced= df.groupby('SKU')['price'].min()
for all the columns you can change the groupby to a list of all the columns you want to keep
df_reduced= df.groupby(['SKU', 'availability', 'Title', 'Supplier'])['price'].min()
and how to test print, print(df_reduced) ?
– user10358702
Mar 27 at 17:00
yes exactly. what you will notice is the SKU is going to take place of the index and if you don't want that you can add as_index=False to the groupby like this df.groupby('SKU', as_index=False)['price'].min()
– D.Sanders
Mar 27 at 17:05
I get key error on SKU
– user10358702
Mar 27 at 17:07
is the column name in the file SKU all caps like that or something else? Its basically saying you aren't putting the correct name for the sku in there. You can get the exact one is using by putting df.columns[0] (or whatever number the SKU column is in place of 0) in place of 'SKU' in the groupby.
– D.Sanders
Mar 27 at 17:10
Your answer returns a dataframe with 2 columns while he wants his result return all columns(after using as_index=False)
– Andy L.
Mar 27 at 18:56
|
show 6 more comments
Edited: taking out the previous confusing assumption
After reading from csv file
In [8]: df = pd.read_csv(filename, delimiter=';', encoding='utf-8')
In [9]: df
Out[9]:
SKU price availability Title Supplier
0 SUV500 21,50 € 1 27-03-2019 14:46 supplier1
1 MZ-76E 5,50 € 1 27-03-2019 14:46 supplier1
2 SUV500 49,95 € 0 27-03-2019 14:46 supplier2
3 MZ-76E 71,25 € 0 27-03-2019 14:46 supplier2
4 SUV500 32,60 € 1 27-03-2019 14:46 supplier3
Add a new columns to hold the float value of price
In [12]: df['f_price'] = df['price'].str.extract(r'([+-]?d+,d+)', expand=False).str.replace(',', '.').astype(float)
#Note: if your locality using denotion `,` for decimal point, you don't need additional `str.replace`. Just use below
#df['f_price'] = df['price'].str.extract(r'([+-]?d+,d+)', expand=True).astype(float)
In [13]: df
Out[13]:
SKU price availability Title Supplier f_price
0 SUV500 21,50 € 1 27-03-2019 14:46 supplier1 21.50
1 MZ-76E 5,50 € 1 27-03-2019 14:46 supplier1 5.50
2 SUV500 49,95 € 0 27-03-2019 14:46 supplier2 49.95
3 MZ-76E 71,25 € 0 27-03-2019 14:46 supplier2 71.25
4 SUV500 32,60 € 1 27-03-2019 14:46 supplier3 32.60
Get the list of min(f_price) per group from groupby
In [28]: idxmin_list = df.groupby('SKU', as_index=False)['f_price'].idxmin().tolist()
In [29]: idxmin_list
Out[29]: [1, 0]
Finally, passing idxmin_list to df and drop f_price column to get the final result
In [33]: df_final = df.loc[idxmin_list].drop('f_price', 1)
In [34]: df_final
Out[34]:
SKU price availability Title Supplier
1 MZ-76E 5,50 € 1 27-03-2019 14:46 supplier1
0 SUV500 21,50 € 1 27-03-2019 14:46 supplier1
Write to csv file
In [65]: df_final.to_csv('Sku_min.csv', sep=';', index=False)
File Sku_min.csv is created in your working folder and its content is
SKU;price;availability;Title;Supplier
MZ-76E;5,50 €;1;27-03-2019 14:46;supplier1
SUV500;21,50 €;1;27-03-2019 14:46;supplier1
The .idxmin().tolist() is not working why?
– user10358702
Apr 3 at 20:15
add a comment |
There's no real need to use pandas here. This may not be the optimal solution but it'd be mine:
import csv
class Product:
def __init__(self, sku, price, availability, title, supplier):
self.sku = sku
self.price = float(price.replace(',', '.')[:-2]) # allows sorting
self.availability = availability
self.title = title
self.supplier = supplier
unparsed_products = []
with open('name_of_csv.csv', 'r') as csvfile:
csv_reader = csv.reader(csvfile, delimiter=';')
next(csv_reader) # to skip past header line when parsing.
for row in csv_reader:
p = Product(*row)
unparsed_products.append(p)
suv500_products = [i for i in unparsed_products if i.sku == 'SUV500']
lowest_priced_suv500_product = sorted(suv500_products, key=lambda x: x.price, reverse=True)[0] # gets the first entry from the sorted list of suv500_products
print(lowest_priced_suv500_product.price)
>>> 21.50
You could easily extend this out to cover other products by changing the value of X in if i.sku == X .
I get that self.price = float(self.price.replace(',', '.')[:-2]) # allows sorting , Product object has no attribute price
– user10358702
Mar 27 at 17:20
Sorry about that - I was referring toself.pricebefore it was defined. That line is fixed now.
– n1c9
Mar 27 at 17:21
Value Error on price could not convert string to float: 'pri' I added .replace('€','') but I get the same
– user10358702
Mar 27 at 17:24
Okay - that error is referring to the header line of the CSV. I have updated the code block to include a line to skip that and marked it with a comment. I've been spoiled by pyspark lately where you can just doheaders=Trueand the rest is magic :-)
– n1c9
Mar 27 at 17:27
1
You'd do something likeprint(lowest_priced_suv500_product.supplier, lowest_priced_suv500_product.price)to get that info to print as well.
– n1c9
Mar 27 at 17:32
|
show 4 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55382525%2fhow-to-find-the-minimum-value-of-a-list-element-which-is-based-on-unique-value-o%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
A non pandas solution, this could get your required output.
EDIT: Added csv writer to solution
EDIT: only accept records with '1' in at row[2]
from collections import defaultdict
import re
from operator import itemgetter
import csv
fin = open('SKU_csv.csv', 'r', encoding="utf8")
csv_reader = csv.reader(fin, delimiter=';')
fout = open('test_out.csv', 'w', newline = '')
csv_writer = csv.writer(fout, delimiter=';')
csv_writer.writerow(next(csv_reader)) # print header
d = defaultdict(list)
for row in csv_reader:
if int(row[2]) != 1:
continue
key = row[0]
val = row[1].replace(',', '.')
price = float(re.search('d+.d+', val).group(0))
d[key].append([row, price])
fin.close()
for arr in d.values():
minimum, _ = min(arr, key=itemgetter(1)) # minimum price (at arr idx 1)
csv_writer.writerow(minimum)
fout.close()
'''
*** test_out.csv contents
SKU;price;availability;Title;Supplier
SUV500;21,50 €;1;27-03-2019 14:46;supplier1
MZ-76E;5,50 €;1;27-03-2019 14:46;supplier1
'''
float(re.search('d+.d+', val).group(0)) is not working with group, and some SKU of products display something like korean?! characters in front
– user10358702
Apr 3 at 20:32
I can't guess why group(0) is not working for you. I worked for me given your sample data. Perhaps you could edit your post to include some of the lines that have those characters. Then get back to me and I'll see if I can help.
– Chris Charley
Apr 3 at 21:37
For the characters I added encoding="utf8" for the writing I think its ok, and for the price I did price = float(val) , what re.search is doing together with group?
– user10358702
Apr 3 at 22:18
@Nikos If its working for you, ok. The regular expressionre.search(...is looking for the digits to convert to a float
– Chris Charley
Apr 3 at 23:51
How can be improved so as to get the minimum based on availability 1?
– user10358702
Apr 11 at 8:08
|
show 1 more comment
A non pandas solution, this could get your required output.
EDIT: Added csv writer to solution
EDIT: only accept records with '1' in at row[2]
from collections import defaultdict
import re
from operator import itemgetter
import csv
fin = open('SKU_csv.csv', 'r', encoding="utf8")
csv_reader = csv.reader(fin, delimiter=';')
fout = open('test_out.csv', 'w', newline = '')
csv_writer = csv.writer(fout, delimiter=';')
csv_writer.writerow(next(csv_reader)) # print header
d = defaultdict(list)
for row in csv_reader:
if int(row[2]) != 1:
continue
key = row[0]
val = row[1].replace(',', '.')
price = float(re.search('d+.d+', val).group(0))
d[key].append([row, price])
fin.close()
for arr in d.values():
minimum, _ = min(arr, key=itemgetter(1)) # minimum price (at arr idx 1)
csv_writer.writerow(minimum)
fout.close()
'''
*** test_out.csv contents
SKU;price;availability;Title;Supplier
SUV500;21,50 €;1;27-03-2019 14:46;supplier1
MZ-76E;5,50 €;1;27-03-2019 14:46;supplier1
'''
float(re.search('d+.d+', val).group(0)) is not working with group, and some SKU of products display something like korean?! characters in front
– user10358702
Apr 3 at 20:32
I can't guess why group(0) is not working for you. I worked for me given your sample data. Perhaps you could edit your post to include some of the lines that have those characters. Then get back to me and I'll see if I can help.
– Chris Charley
Apr 3 at 21:37
For the characters I added encoding="utf8" for the writing I think its ok, and for the price I did price = float(val) , what re.search is doing together with group?
– user10358702
Apr 3 at 22:18
@Nikos If its working for you, ok. The regular expressionre.search(...is looking for the digits to convert to a float
– Chris Charley
Apr 3 at 23:51
How can be improved so as to get the minimum based on availability 1?
– user10358702
Apr 11 at 8:08
|
show 1 more comment
A non pandas solution, this could get your required output.
EDIT: Added csv writer to solution
EDIT: only accept records with '1' in at row[2]
from collections import defaultdict
import re
from operator import itemgetter
import csv
fin = open('SKU_csv.csv', 'r', encoding="utf8")
csv_reader = csv.reader(fin, delimiter=';')
fout = open('test_out.csv', 'w', newline = '')
csv_writer = csv.writer(fout, delimiter=';')
csv_writer.writerow(next(csv_reader)) # print header
d = defaultdict(list)
for row in csv_reader:
if int(row[2]) != 1:
continue
key = row[0]
val = row[1].replace(',', '.')
price = float(re.search('d+.d+', val).group(0))
d[key].append([row, price])
fin.close()
for arr in d.values():
minimum, _ = min(arr, key=itemgetter(1)) # minimum price (at arr idx 1)
csv_writer.writerow(minimum)
fout.close()
'''
*** test_out.csv contents
SKU;price;availability;Title;Supplier
SUV500;21,50 €;1;27-03-2019 14:46;supplier1
MZ-76E;5,50 €;1;27-03-2019 14:46;supplier1
'''
A non pandas solution, this could get your required output.
EDIT: Added csv writer to solution
EDIT: only accept records with '1' in at row[2]
from collections import defaultdict
import re
from operator import itemgetter
import csv
fin = open('SKU_csv.csv', 'r', encoding="utf8")
csv_reader = csv.reader(fin, delimiter=';')
fout = open('test_out.csv', 'w', newline = '')
csv_writer = csv.writer(fout, delimiter=';')
csv_writer.writerow(next(csv_reader)) # print header
d = defaultdict(list)
for row in csv_reader:
if int(row[2]) != 1:
continue
key = row[0]
val = row[1].replace(',', '.')
price = float(re.search('d+.d+', val).group(0))
d[key].append([row, price])
fin.close()
for arr in d.values():
minimum, _ = min(arr, key=itemgetter(1)) # minimum price (at arr idx 1)
csv_writer.writerow(minimum)
fout.close()
'''
*** test_out.csv contents
SKU;price;availability;Title;Supplier
SUV500;21,50 €;1;27-03-2019 14:46;supplier1
MZ-76E;5,50 €;1;27-03-2019 14:46;supplier1
'''
edited Apr 11 at 22:18
answered Mar 27 at 22:35
Chris CharleyChris Charley
4,3072 gold badges16 silver badges20 bronze badges
4,3072 gold badges16 silver badges20 bronze badges
float(re.search('d+.d+', val).group(0)) is not working with group, and some SKU of products display something like korean?! characters in front
– user10358702
Apr 3 at 20:32
I can't guess why group(0) is not working for you. I worked for me given your sample data. Perhaps you could edit your post to include some of the lines that have those characters. Then get back to me and I'll see if I can help.
– Chris Charley
Apr 3 at 21:37
For the characters I added encoding="utf8" for the writing I think its ok, and for the price I did price = float(val) , what re.search is doing together with group?
– user10358702
Apr 3 at 22:18
@Nikos If its working for you, ok. The regular expressionre.search(...is looking for the digits to convert to a float
– Chris Charley
Apr 3 at 23:51
How can be improved so as to get the minimum based on availability 1?
– user10358702
Apr 11 at 8:08
|
show 1 more comment
float(re.search('d+.d+', val).group(0)) is not working with group, and some SKU of products display something like korean?! characters in front
– user10358702
Apr 3 at 20:32
I can't guess why group(0) is not working for you. I worked for me given your sample data. Perhaps you could edit your post to include some of the lines that have those characters. Then get back to me and I'll see if I can help.
– Chris Charley
Apr 3 at 21:37
For the characters I added encoding="utf8" for the writing I think its ok, and for the price I did price = float(val) , what re.search is doing together with group?
– user10358702
Apr 3 at 22:18
@Nikos If its working for you, ok. The regular expressionre.search(...is looking for the digits to convert to a float
– Chris Charley
Apr 3 at 23:51
How can be improved so as to get the minimum based on availability 1?
– user10358702
Apr 11 at 8:08
float(re.search('d+.d+', val).group(0)) is not working with group, and some SKU of products display something like korean?! characters in front
– user10358702
Apr 3 at 20:32
float(re.search('d+.d+', val).group(0)) is not working with group, and some SKU of products display something like korean?! characters in front
– user10358702
Apr 3 at 20:32
I can't guess why group(0) is not working for you. I worked for me given your sample data. Perhaps you could edit your post to include some of the lines that have those characters. Then get back to me and I'll see if I can help.
– Chris Charley
Apr 3 at 21:37
I can't guess why group(0) is not working for you. I worked for me given your sample data. Perhaps you could edit your post to include some of the lines that have those characters. Then get back to me and I'll see if I can help.
– Chris Charley
Apr 3 at 21:37
For the characters I added encoding="utf8" for the writing I think its ok, and for the price I did price = float(val) , what re.search is doing together with group?
– user10358702
Apr 3 at 22:18
For the characters I added encoding="utf8" for the writing I think its ok, and for the price I did price = float(val) , what re.search is doing together with group?
– user10358702
Apr 3 at 22:18
@Nikos If its working for you, ok. The regular expression
re.search(... is looking for the digits to convert to a float– Chris Charley
Apr 3 at 23:51
@Nikos If its working for you, ok. The regular expression
re.search(... is looking for the digits to convert to a float– Chris Charley
Apr 3 at 23:51
How can be improved so as to get the minimum based on availability 1?
– user10358702
Apr 11 at 8:08
How can be improved so as to get the minimum based on availability 1?
– user10358702
Apr 11 at 8:08
|
show 1 more comment
In pandas you can do the following
import pandas as pd
df= pd.read_csv('your file')
As andy pointed out below this returns only the price and SKU columns
df_reduced= df.groupby('SKU')['price'].min()
for all the columns you can change the groupby to a list of all the columns you want to keep
df_reduced= df.groupby(['SKU', 'availability', 'Title', 'Supplier'])['price'].min()
and how to test print, print(df_reduced) ?
– user10358702
Mar 27 at 17:00
yes exactly. what you will notice is the SKU is going to take place of the index and if you don't want that you can add as_index=False to the groupby like this df.groupby('SKU', as_index=False)['price'].min()
– D.Sanders
Mar 27 at 17:05
I get key error on SKU
– user10358702
Mar 27 at 17:07
is the column name in the file SKU all caps like that or something else? Its basically saying you aren't putting the correct name for the sku in there. You can get the exact one is using by putting df.columns[0] (or whatever number the SKU column is in place of 0) in place of 'SKU' in the groupby.
– D.Sanders
Mar 27 at 17:10
Your answer returns a dataframe with 2 columns while he wants his result return all columns(after using as_index=False)
– Andy L.
Mar 27 at 18:56
|
show 6 more comments
In pandas you can do the following
import pandas as pd
df= pd.read_csv('your file')
As andy pointed out below this returns only the price and SKU columns
df_reduced= df.groupby('SKU')['price'].min()
for all the columns you can change the groupby to a list of all the columns you want to keep
df_reduced= df.groupby(['SKU', 'availability', 'Title', 'Supplier'])['price'].min()
and how to test print, print(df_reduced) ?
– user10358702
Mar 27 at 17:00
yes exactly. what you will notice is the SKU is going to take place of the index and if you don't want that you can add as_index=False to the groupby like this df.groupby('SKU', as_index=False)['price'].min()
– D.Sanders
Mar 27 at 17:05
I get key error on SKU
– user10358702
Mar 27 at 17:07
is the column name in the file SKU all caps like that or something else? Its basically saying you aren't putting the correct name for the sku in there. You can get the exact one is using by putting df.columns[0] (or whatever number the SKU column is in place of 0) in place of 'SKU' in the groupby.
– D.Sanders
Mar 27 at 17:10
Your answer returns a dataframe with 2 columns while he wants his result return all columns(after using as_index=False)
– Andy L.
Mar 27 at 18:56
|
show 6 more comments
In pandas you can do the following
import pandas as pd
df= pd.read_csv('your file')
As andy pointed out below this returns only the price and SKU columns
df_reduced= df.groupby('SKU')['price'].min()
for all the columns you can change the groupby to a list of all the columns you want to keep
df_reduced= df.groupby(['SKU', 'availability', 'Title', 'Supplier'])['price'].min()
In pandas you can do the following
import pandas as pd
df= pd.read_csv('your file')
As andy pointed out below this returns only the price and SKU columns
df_reduced= df.groupby('SKU')['price'].min()
for all the columns you can change the groupby to a list of all the columns you want to keep
df_reduced= df.groupby(['SKU', 'availability', 'Title', 'Supplier'])['price'].min()
edited Mar 27 at 19:13
answered Mar 27 at 16:57
D.SandersD.Sanders
906 bronze badges
906 bronze badges
and how to test print, print(df_reduced) ?
– user10358702
Mar 27 at 17:00
yes exactly. what you will notice is the SKU is going to take place of the index and if you don't want that you can add as_index=False to the groupby like this df.groupby('SKU', as_index=False)['price'].min()
– D.Sanders
Mar 27 at 17:05
I get key error on SKU
– user10358702
Mar 27 at 17:07
is the column name in the file SKU all caps like that or something else? Its basically saying you aren't putting the correct name for the sku in there. You can get the exact one is using by putting df.columns[0] (or whatever number the SKU column is in place of 0) in place of 'SKU' in the groupby.
– D.Sanders
Mar 27 at 17:10
Your answer returns a dataframe with 2 columns while he wants his result return all columns(after using as_index=False)
– Andy L.
Mar 27 at 18:56
|
show 6 more comments
and how to test print, print(df_reduced) ?
– user10358702
Mar 27 at 17:00
yes exactly. what you will notice is the SKU is going to take place of the index and if you don't want that you can add as_index=False to the groupby like this df.groupby('SKU', as_index=False)['price'].min()
– D.Sanders
Mar 27 at 17:05
I get key error on SKU
– user10358702
Mar 27 at 17:07
is the column name in the file SKU all caps like that or something else? Its basically saying you aren't putting the correct name for the sku in there. You can get the exact one is using by putting df.columns[0] (or whatever number the SKU column is in place of 0) in place of 'SKU' in the groupby.
– D.Sanders
Mar 27 at 17:10
Your answer returns a dataframe with 2 columns while he wants his result return all columns(after using as_index=False)
– Andy L.
Mar 27 at 18:56
and how to test print, print(df_reduced) ?
– user10358702
Mar 27 at 17:00
and how to test print, print(df_reduced) ?
– user10358702
Mar 27 at 17:00
yes exactly. what you will notice is the SKU is going to take place of the index and if you don't want that you can add as_index=False to the groupby like this df.groupby('SKU', as_index=False)['price'].min()
– D.Sanders
Mar 27 at 17:05
yes exactly. what you will notice is the SKU is going to take place of the index and if you don't want that you can add as_index=False to the groupby like this df.groupby('SKU', as_index=False)['price'].min()
– D.Sanders
Mar 27 at 17:05
I get key error on SKU
– user10358702
Mar 27 at 17:07
I get key error on SKU
– user10358702
Mar 27 at 17:07
is the column name in the file SKU all caps like that or something else? Its basically saying you aren't putting the correct name for the sku in there. You can get the exact one is using by putting df.columns[0] (or whatever number the SKU column is in place of 0) in place of 'SKU' in the groupby.
– D.Sanders
Mar 27 at 17:10
is the column name in the file SKU all caps like that or something else? Its basically saying you aren't putting the correct name for the sku in there. You can get the exact one is using by putting df.columns[0] (or whatever number the SKU column is in place of 0) in place of 'SKU' in the groupby.
– D.Sanders
Mar 27 at 17:10
Your answer returns a dataframe with 2 columns while he wants his result return all columns(after using as_index=False)
– Andy L.
Mar 27 at 18:56
Your answer returns a dataframe with 2 columns while he wants his result return all columns(after using as_index=False)
– Andy L.
Mar 27 at 18:56
|
show 6 more comments
Edited: taking out the previous confusing assumption
After reading from csv file
In [8]: df = pd.read_csv(filename, delimiter=';', encoding='utf-8')
In [9]: df
Out[9]:
SKU price availability Title Supplier
0 SUV500 21,50 € 1 27-03-2019 14:46 supplier1
1 MZ-76E 5,50 € 1 27-03-2019 14:46 supplier1
2 SUV500 49,95 € 0 27-03-2019 14:46 supplier2
3 MZ-76E 71,25 € 0 27-03-2019 14:46 supplier2
4 SUV500 32,60 € 1 27-03-2019 14:46 supplier3
Add a new columns to hold the float value of price
In [12]: df['f_price'] = df['price'].str.extract(r'([+-]?d+,d+)', expand=False).str.replace(',', '.').astype(float)
#Note: if your locality using denotion `,` for decimal point, you don't need additional `str.replace`. Just use below
#df['f_price'] = df['price'].str.extract(r'([+-]?d+,d+)', expand=True).astype(float)
In [13]: df
Out[13]:
SKU price availability Title Supplier f_price
0 SUV500 21,50 € 1 27-03-2019 14:46 supplier1 21.50
1 MZ-76E 5,50 € 1 27-03-2019 14:46 supplier1 5.50
2 SUV500 49,95 € 0 27-03-2019 14:46 supplier2 49.95
3 MZ-76E 71,25 € 0 27-03-2019 14:46 supplier2 71.25
4 SUV500 32,60 € 1 27-03-2019 14:46 supplier3 32.60
Get the list of min(f_price) per group from groupby
In [28]: idxmin_list = df.groupby('SKU', as_index=False)['f_price'].idxmin().tolist()
In [29]: idxmin_list
Out[29]: [1, 0]
Finally, passing idxmin_list to df and drop f_price column to get the final result
In [33]: df_final = df.loc[idxmin_list].drop('f_price', 1)
In [34]: df_final
Out[34]:
SKU price availability Title Supplier
1 MZ-76E 5,50 € 1 27-03-2019 14:46 supplier1
0 SUV500 21,50 € 1 27-03-2019 14:46 supplier1
Write to csv file
In [65]: df_final.to_csv('Sku_min.csv', sep=';', index=False)
File Sku_min.csv is created in your working folder and its content is
SKU;price;availability;Title;Supplier
MZ-76E;5,50 €;1;27-03-2019 14:46;supplier1
SUV500;21,50 €;1;27-03-2019 14:46;supplier1
The .idxmin().tolist() is not working why?
– user10358702
Apr 3 at 20:15
add a comment |
Edited: taking out the previous confusing assumption
After reading from csv file
In [8]: df = pd.read_csv(filename, delimiter=';', encoding='utf-8')
In [9]: df
Out[9]:
SKU price availability Title Supplier
0 SUV500 21,50 € 1 27-03-2019 14:46 supplier1
1 MZ-76E 5,50 € 1 27-03-2019 14:46 supplier1
2 SUV500 49,95 € 0 27-03-2019 14:46 supplier2
3 MZ-76E 71,25 € 0 27-03-2019 14:46 supplier2
4 SUV500 32,60 € 1 27-03-2019 14:46 supplier3
Add a new columns to hold the float value of price
In [12]: df['f_price'] = df['price'].str.extract(r'([+-]?d+,d+)', expand=False).str.replace(',', '.').astype(float)
#Note: if your locality using denotion `,` for decimal point, you don't need additional `str.replace`. Just use below
#df['f_price'] = df['price'].str.extract(r'([+-]?d+,d+)', expand=True).astype(float)
In [13]: df
Out[13]:
SKU price availability Title Supplier f_price
0 SUV500 21,50 € 1 27-03-2019 14:46 supplier1 21.50
1 MZ-76E 5,50 € 1 27-03-2019 14:46 supplier1 5.50
2 SUV500 49,95 € 0 27-03-2019 14:46 supplier2 49.95
3 MZ-76E 71,25 € 0 27-03-2019 14:46 supplier2 71.25
4 SUV500 32,60 € 1 27-03-2019 14:46 supplier3 32.60
Get the list of min(f_price) per group from groupby
In [28]: idxmin_list = df.groupby('SKU', as_index=False)['f_price'].idxmin().tolist()
In [29]: idxmin_list
Out[29]: [1, 0]
Finally, passing idxmin_list to df and drop f_price column to get the final result
In [33]: df_final = df.loc[idxmin_list].drop('f_price', 1)
In [34]: df_final
Out[34]:
SKU price availability Title Supplier
1 MZ-76E 5,50 € 1 27-03-2019 14:46 supplier1
0 SUV500 21,50 € 1 27-03-2019 14:46 supplier1
Write to csv file
In [65]: df_final.to_csv('Sku_min.csv', sep=';', index=False)
File Sku_min.csv is created in your working folder and its content is
SKU;price;availability;Title;Supplier
MZ-76E;5,50 €;1;27-03-2019 14:46;supplier1
SUV500;21,50 €;1;27-03-2019 14:46;supplier1
The .idxmin().tolist() is not working why?
– user10358702
Apr 3 at 20:15
add a comment |
Edited: taking out the previous confusing assumption
After reading from csv file
In [8]: df = pd.read_csv(filename, delimiter=';', encoding='utf-8')
In [9]: df
Out[9]:
SKU price availability Title Supplier
0 SUV500 21,50 € 1 27-03-2019 14:46 supplier1
1 MZ-76E 5,50 € 1 27-03-2019 14:46 supplier1
2 SUV500 49,95 € 0 27-03-2019 14:46 supplier2
3 MZ-76E 71,25 € 0 27-03-2019 14:46 supplier2
4 SUV500 32,60 € 1 27-03-2019 14:46 supplier3
Add a new columns to hold the float value of price
In [12]: df['f_price'] = df['price'].str.extract(r'([+-]?d+,d+)', expand=False).str.replace(',', '.').astype(float)
#Note: if your locality using denotion `,` for decimal point, you don't need additional `str.replace`. Just use below
#df['f_price'] = df['price'].str.extract(r'([+-]?d+,d+)', expand=True).astype(float)
In [13]: df
Out[13]:
SKU price availability Title Supplier f_price
0 SUV500 21,50 € 1 27-03-2019 14:46 supplier1 21.50
1 MZ-76E 5,50 € 1 27-03-2019 14:46 supplier1 5.50
2 SUV500 49,95 € 0 27-03-2019 14:46 supplier2 49.95
3 MZ-76E 71,25 € 0 27-03-2019 14:46 supplier2 71.25
4 SUV500 32,60 € 1 27-03-2019 14:46 supplier3 32.60
Get the list of min(f_price) per group from groupby
In [28]: idxmin_list = df.groupby('SKU', as_index=False)['f_price'].idxmin().tolist()
In [29]: idxmin_list
Out[29]: [1, 0]
Finally, passing idxmin_list to df and drop f_price column to get the final result
In [33]: df_final = df.loc[idxmin_list].drop('f_price', 1)
In [34]: df_final
Out[34]:
SKU price availability Title Supplier
1 MZ-76E 5,50 € 1 27-03-2019 14:46 supplier1
0 SUV500 21,50 € 1 27-03-2019 14:46 supplier1
Write to csv file
In [65]: df_final.to_csv('Sku_min.csv', sep=';', index=False)
File Sku_min.csv is created in your working folder and its content is
SKU;price;availability;Title;Supplier
MZ-76E;5,50 €;1;27-03-2019 14:46;supplier1
SUV500;21,50 €;1;27-03-2019 14:46;supplier1
Edited: taking out the previous confusing assumption
After reading from csv file
In [8]: df = pd.read_csv(filename, delimiter=';', encoding='utf-8')
In [9]: df
Out[9]:
SKU price availability Title Supplier
0 SUV500 21,50 € 1 27-03-2019 14:46 supplier1
1 MZ-76E 5,50 € 1 27-03-2019 14:46 supplier1
2 SUV500 49,95 € 0 27-03-2019 14:46 supplier2
3 MZ-76E 71,25 € 0 27-03-2019 14:46 supplier2
4 SUV500 32,60 € 1 27-03-2019 14:46 supplier3
Add a new columns to hold the float value of price
In [12]: df['f_price'] = df['price'].str.extract(r'([+-]?d+,d+)', expand=False).str.replace(',', '.').astype(float)
#Note: if your locality using denotion `,` for decimal point, you don't need additional `str.replace`. Just use below
#df['f_price'] = df['price'].str.extract(r'([+-]?d+,d+)', expand=True).astype(float)
In [13]: df
Out[13]:
SKU price availability Title Supplier f_price
0 SUV500 21,50 € 1 27-03-2019 14:46 supplier1 21.50
1 MZ-76E 5,50 € 1 27-03-2019 14:46 supplier1 5.50
2 SUV500 49,95 € 0 27-03-2019 14:46 supplier2 49.95
3 MZ-76E 71,25 € 0 27-03-2019 14:46 supplier2 71.25
4 SUV500 32,60 € 1 27-03-2019 14:46 supplier3 32.60
Get the list of min(f_price) per group from groupby
In [28]: idxmin_list = df.groupby('SKU', as_index=False)['f_price'].idxmin().tolist()
In [29]: idxmin_list
Out[29]: [1, 0]
Finally, passing idxmin_list to df and drop f_price column to get the final result
In [33]: df_final = df.loc[idxmin_list].drop('f_price', 1)
In [34]: df_final
Out[34]:
SKU price availability Title Supplier
1 MZ-76E 5,50 € 1 27-03-2019 14:46 supplier1
0 SUV500 21,50 € 1 27-03-2019 14:46 supplier1
Write to csv file
In [65]: df_final.to_csv('Sku_min.csv', sep=';', index=False)
File Sku_min.csv is created in your working folder and its content is
SKU;price;availability;Title;Supplier
MZ-76E;5,50 €;1;27-03-2019 14:46;supplier1
SUV500;21,50 €;1;27-03-2019 14:46;supplier1
edited Mar 28 at 0:58
answered Mar 27 at 23:41
Andy L.Andy L.
4,6071 gold badge3 silver badges16 bronze badges
4,6071 gold badge3 silver badges16 bronze badges
The .idxmin().tolist() is not working why?
– user10358702
Apr 3 at 20:15
add a comment |
The .idxmin().tolist() is not working why?
– user10358702
Apr 3 at 20:15
The .idxmin().tolist() is not working why?
– user10358702
Apr 3 at 20:15
The .idxmin().tolist() is not working why?
– user10358702
Apr 3 at 20:15
add a comment |
There's no real need to use pandas here. This may not be the optimal solution but it'd be mine:
import csv
class Product:
def __init__(self, sku, price, availability, title, supplier):
self.sku = sku
self.price = float(price.replace(',', '.')[:-2]) # allows sorting
self.availability = availability
self.title = title
self.supplier = supplier
unparsed_products = []
with open('name_of_csv.csv', 'r') as csvfile:
csv_reader = csv.reader(csvfile, delimiter=';')
next(csv_reader) # to skip past header line when parsing.
for row in csv_reader:
p = Product(*row)
unparsed_products.append(p)
suv500_products = [i for i in unparsed_products if i.sku == 'SUV500']
lowest_priced_suv500_product = sorted(suv500_products, key=lambda x: x.price, reverse=True)[0] # gets the first entry from the sorted list of suv500_products
print(lowest_priced_suv500_product.price)
>>> 21.50
You could easily extend this out to cover other products by changing the value of X in if i.sku == X .
I get that self.price = float(self.price.replace(',', '.')[:-2]) # allows sorting , Product object has no attribute price
– user10358702
Mar 27 at 17:20
Sorry about that - I was referring toself.pricebefore it was defined. That line is fixed now.
– n1c9
Mar 27 at 17:21
Value Error on price could not convert string to float: 'pri' I added .replace('€','') but I get the same
– user10358702
Mar 27 at 17:24
Okay - that error is referring to the header line of the CSV. I have updated the code block to include a line to skip that and marked it with a comment. I've been spoiled by pyspark lately where you can just doheaders=Trueand the rest is magic :-)
– n1c9
Mar 27 at 17:27
1
You'd do something likeprint(lowest_priced_suv500_product.supplier, lowest_priced_suv500_product.price)to get that info to print as well.
– n1c9
Mar 27 at 17:32
|
show 4 more comments
There's no real need to use pandas here. This may not be the optimal solution but it'd be mine:
import csv
class Product:
def __init__(self, sku, price, availability, title, supplier):
self.sku = sku
self.price = float(price.replace(',', '.')[:-2]) # allows sorting
self.availability = availability
self.title = title
self.supplier = supplier
unparsed_products = []
with open('name_of_csv.csv', 'r') as csvfile:
csv_reader = csv.reader(csvfile, delimiter=';')
next(csv_reader) # to skip past header line when parsing.
for row in csv_reader:
p = Product(*row)
unparsed_products.append(p)
suv500_products = [i for i in unparsed_products if i.sku == 'SUV500']
lowest_priced_suv500_product = sorted(suv500_products, key=lambda x: x.price, reverse=True)[0] # gets the first entry from the sorted list of suv500_products
print(lowest_priced_suv500_product.price)
>>> 21.50
You could easily extend this out to cover other products by changing the value of X in if i.sku == X .
I get that self.price = float(self.price.replace(',', '.')[:-2]) # allows sorting , Product object has no attribute price
– user10358702
Mar 27 at 17:20
Sorry about that - I was referring toself.pricebefore it was defined. That line is fixed now.
– n1c9
Mar 27 at 17:21
Value Error on price could not convert string to float: 'pri' I added .replace('€','') but I get the same
– user10358702
Mar 27 at 17:24
Okay - that error is referring to the header line of the CSV. I have updated the code block to include a line to skip that and marked it with a comment. I've been spoiled by pyspark lately where you can just doheaders=Trueand the rest is magic :-)
– n1c9
Mar 27 at 17:27
1
You'd do something likeprint(lowest_priced_suv500_product.supplier, lowest_priced_suv500_product.price)to get that info to print as well.
– n1c9
Mar 27 at 17:32
|
show 4 more comments
There's no real need to use pandas here. This may not be the optimal solution but it'd be mine:
import csv
class Product:
def __init__(self, sku, price, availability, title, supplier):
self.sku = sku
self.price = float(price.replace(',', '.')[:-2]) # allows sorting
self.availability = availability
self.title = title
self.supplier = supplier
unparsed_products = []
with open('name_of_csv.csv', 'r') as csvfile:
csv_reader = csv.reader(csvfile, delimiter=';')
next(csv_reader) # to skip past header line when parsing.
for row in csv_reader:
p = Product(*row)
unparsed_products.append(p)
suv500_products = [i for i in unparsed_products if i.sku == 'SUV500']
lowest_priced_suv500_product = sorted(suv500_products, key=lambda x: x.price, reverse=True)[0] # gets the first entry from the sorted list of suv500_products
print(lowest_priced_suv500_product.price)
>>> 21.50
You could easily extend this out to cover other products by changing the value of X in if i.sku == X .
There's no real need to use pandas here. This may not be the optimal solution but it'd be mine:
import csv
class Product:
def __init__(self, sku, price, availability, title, supplier):
self.sku = sku
self.price = float(price.replace(',', '.')[:-2]) # allows sorting
self.availability = availability
self.title = title
self.supplier = supplier
unparsed_products = []
with open('name_of_csv.csv', 'r') as csvfile:
csv_reader = csv.reader(csvfile, delimiter=';')
next(csv_reader) # to skip past header line when parsing.
for row in csv_reader:
p = Product(*row)
unparsed_products.append(p)
suv500_products = [i for i in unparsed_products if i.sku == 'SUV500']
lowest_priced_suv500_product = sorted(suv500_products, key=lambda x: x.price, reverse=True)[0] # gets the first entry from the sorted list of suv500_products
print(lowest_priced_suv500_product.price)
>>> 21.50
You could easily extend this out to cover other products by changing the value of X in if i.sku == X .
edited Apr 17 at 16:24
answered Mar 27 at 17:07
n1c9n1c9
1,8282 gold badges18 silver badges36 bronze badges
1,8282 gold badges18 silver badges36 bronze badges
I get that self.price = float(self.price.replace(',', '.')[:-2]) # allows sorting , Product object has no attribute price
– user10358702
Mar 27 at 17:20
Sorry about that - I was referring toself.pricebefore it was defined. That line is fixed now.
– n1c9
Mar 27 at 17:21
Value Error on price could not convert string to float: 'pri' I added .replace('€','') but I get the same
– user10358702
Mar 27 at 17:24
Okay - that error is referring to the header line of the CSV. I have updated the code block to include a line to skip that and marked it with a comment. I've been spoiled by pyspark lately where you can just doheaders=Trueand the rest is magic :-)
– n1c9
Mar 27 at 17:27
1
You'd do something likeprint(lowest_priced_suv500_product.supplier, lowest_priced_suv500_product.price)to get that info to print as well.
– n1c9
Mar 27 at 17:32
|
show 4 more comments
I get that self.price = float(self.price.replace(',', '.')[:-2]) # allows sorting , Product object has no attribute price
– user10358702
Mar 27 at 17:20
Sorry about that - I was referring toself.pricebefore it was defined. That line is fixed now.
– n1c9
Mar 27 at 17:21
Value Error on price could not convert string to float: 'pri' I added .replace('€','') but I get the same
– user10358702
Mar 27 at 17:24
Okay - that error is referring to the header line of the CSV. I have updated the code block to include a line to skip that and marked it with a comment. I've been spoiled by pyspark lately where you can just doheaders=Trueand the rest is magic :-)
– n1c9
Mar 27 at 17:27
1
You'd do something likeprint(lowest_priced_suv500_product.supplier, lowest_priced_suv500_product.price)to get that info to print as well.
– n1c9
Mar 27 at 17:32
I get that self.price = float(self.price.replace(',', '.')[:-2]) # allows sorting , Product object has no attribute price
– user10358702
Mar 27 at 17:20
I get that self.price = float(self.price.replace(',', '.')[:-2]) # allows sorting , Product object has no attribute price
– user10358702
Mar 27 at 17:20
Sorry about that - I was referring to
self.price before it was defined. That line is fixed now.– n1c9
Mar 27 at 17:21
Sorry about that - I was referring to
self.price before it was defined. That line is fixed now.– n1c9
Mar 27 at 17:21
Value Error on price could not convert string to float: 'pri' I added .replace('€','') but I get the same
– user10358702
Mar 27 at 17:24
Value Error on price could not convert string to float: 'pri' I added .replace('€','') but I get the same
– user10358702
Mar 27 at 17:24
Okay - that error is referring to the header line of the CSV. I have updated the code block to include a line to skip that and marked it with a comment. I've been spoiled by pyspark lately where you can just do
headers=True and the rest is magic :-)– n1c9
Mar 27 at 17:27
Okay - that error is referring to the header line of the CSV. I have updated the code block to include a line to skip that and marked it with a comment. I've been spoiled by pyspark lately where you can just do
headers=True and the rest is magic :-)– n1c9
Mar 27 at 17:27
1
1
You'd do something like
print(lowest_priced_suv500_product.supplier, lowest_priced_suv500_product.price) to get that info to print as well.– n1c9
Mar 27 at 17:32
You'd do something like
print(lowest_priced_suv500_product.supplier, lowest_priced_suv500_product.price) to get that info to print as well.– n1c9
Mar 27 at 17:32
|
show 4 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55382525%2fhow-to-find-the-minimum-value-of-a-list-element-which-is-based-on-unique-value-o%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown