Comments (7)
I agree with you. I think the answer provide is simply wrong.
from pandas_exercises.
I agree too. However, to get the number of products costing more than $10.00, I believe you could use a simpler command:
chipo.loc[chipo['item_price']/chipo['quantity'] > 10, 'item_name'].drop_duplicates().shape[0]
Hope this helps other newcomers.
from pandas_exercises.
I came up with the same issue. The question needs to be reconsidered, or the proposed solution changed. I believe the number of unique products with a price higher than 10 is 31. I use this code, after changing the column to float:
chipo[chipo['item_price']>10]['item_name'].nunique()
from pandas_exercises.
@bromero26 I get the same answer as you using a slightly more verbose method:
min_max_price_per_item = chipo.groupby('item_name').agg({'item_price': [np.max, np.min]})
min_max_price_per_item[min_max_price_per_item.item_price.amax > 10].shape[0]
But all of those high prices are caused by extras or specific configurations. If you stick to the basics, any item can be had for less than $10:
min_max_price_per_item[min_max_price_per_item.item_price.amin > 10].shape[0]
The question is not well-formed. It could be asking:
- Which products did at least one person order for more than $10? (A: 31)
- Which products always cost at least $10, regardless of choice_description? (A: 0)
- Which product combinations (combination of item_name and choice_description) cost at least $10? (A: 777)
from pandas_exercises.
@rahimnathwani I agree with you, the question is not well-formed. Still, I believe that @matiascalderini suggestion is correct since price vs quantity seems quite linear. Check using water bottles as an example:
(
chipo.query('item_name == "Bottled Water"')[['quantity', 'item_price']]
.groupby('quantity')
.agg(['mean', 'std'])
.item_price
.reset_index()
.plot(x='quantity', y='mean', yerr='std', kind='scatter')
)
Normalizing the cost I get these values:
chipo['price_per_item'] = chipo.item_price/chipo.quantity
A1 = chipo.query('price_per_item > 10').item_name.nunique()
A2 = (chipo.groupby('item_name').price_per_item.min()>10).sum()
chipo['name_with_variants'] = chipo.item_name+chipo.choice_description
A3 = (chipo.groupby('name_with_variants').price_per_item.min()>10).sum()
print(f'A1:{A1}, A2:{A2}, A3:{A3}')
A1:25, A2:0, A3:707
from pandas_exercises.
Hi everyone, thank you for the comments and feedback. I agree that this question is not so clear too.
Some clarifications:
- There is a clear distinction of
order_id
,quantity
andproduct
. Example, in a sameorder_id
, you can ask aproduct
in aquantity
greater than 1, which will influence the price.
Example:
order _id | quantity | item_name | choice_description | item_price
9 | 2 | Canned Soda | [Sprite] | $2.18
14 | 1 | Canned Soda | [Dr. Pepper] | $1.09
Canned Soda costs $1.09. If I buy 10 sodas, the line will show up $10.90, which is greater than $10, but that doesn't mean that the product Canned Soda costs more than $10.
That is the reason that quantity needs to be considered for this exercise.
- In order to simplify the exercise take the combination of
item_name + choice_description
as "one product".
Example:
order _id | quantity | item_name | choice_description | item_price
12 | 1 | Chicken Burrito | [[Tomatillo-Green Chili Salsa (Medium), Tomati... | $10.98
8 | 1 | Chicken Burrito | [Tomatillo-Green Chili Salsa (Medium), [Pinto ... | $8.49
"Chicken Burrito" is the "main" product but depending on the additional items it will cost more or less than $10, so to simplify take the combination item_name + choice_description
as "one product".
Considering that what is your suggestion? Send me a PR! π
from pandas_exercises.
In the getting and knowing your data part ,the url donnot work.what should I do?
from pandas_exercises.
Related Issues (20)
- New to GitHub HOT 2
- Question: Is Step 9 solution correct? HOT 1
- Can I translate this code into Korean and post it on my blog?
- Getting Financial Data - Pandas Datareader - Step 8 Solution HOT 1
- 01_Getting_&_Knowing_Your_Data - Chipotle - Total Revenue Incorrect HOT 1
- Pandas Application HOT 1
- 'Chips and Roasted Chili-Corn Salsa' and 'Chips and Roasted Chili Corn Salsa' is duplicated?
- 02 Filtering on Euro 12
- impossible to type code in windows. What is fail? HOT 1
- Missing β09_Time_SeriesGetting_Financial_Dataβ solution code HOT 1
- Faster Alternative to 01_Getting_&_Knowing_Your_Data - World Food Facts Step 11
- Alternative to pandas_exercises/03_Grouping/Occupation/ Step 8
- 01_Getting_&_Knowing_Your_Data/Chipotle/Exercise_with_Solutions.ipynb - Step 13.b : Incorrect solution? HOT 1
- What's the code is about
- f
- new code issue
- pandas_exercises/03_Grouping/Occupation /Exercises_with_solutions.ipynb video link not working
- small typos
- error in 03_Grouping/Alcohol_Consumption/Exercise_with_solutions.ipynb
- Very good source to practise pandas
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pandas_exercises.