COMP9321代做、Python设计程序代写
COMP9321 25T1 Assignment 1 (15 marks)

Introduction

The NSW FuelCheck dataset is maintained by the NSW Government. It allows motorists

to access historical and live information about fuel prices across NSW. We have

downloaded the “FuelCheck Price History Jan 2025” file in February 2025 and are

storing it locally for your use as fuel.csv.

A dataset of Australian postcodes, with their latitudes and longitudes, is also available

from the user “Elkfox” on Github. This has been stored locally for your use in February

2025 as postcodes.json.

You're encouraged to review these and explore these datasets prior to attempting the

assignment. Please note that this data is publicly available, and we are not responsible

for political correctness, or other data inaccuracies, as this is purely a learning exercise

for data services engineering. Accompanying each question below you'll find:

Output: This includes the expected shape of the DataFrame to return.

Marking Considerations: These, along with the expected output, are provided to help

you stay on track. They serve as marking guidance to help you understand how we mark

the assessment.

Code Template

You must use the code template and rename the code template with your zID.

You must not modify the code template, except where indicated. For example, you

must not:

? Import additional third-party libraries.

? Modify the function signature for each question_X function.

? Modify the main function.

? Modify the log function.

? Disable or modify the calls to the log and plt.savefig functions within each

question_X function.

? Add any global variables.

You must setup a virtual environment as per the provided requirements.txt and

instructions here.

You must use either Python 3.11 (which is installed on CSE) or Python 3.13 (which is the

current release).

You must use pandas features to solve all question.

You must not iterate over the rows of any DataFrame.

For clarity, any `for` or `while`

loop that runs proportionally to the number of rows in a DataFrame is iterating over the

rows of that DataFrame. This also holds for any Series, for example, iterating over one

column of a DataFrame.

However, uou may iterate over DataFrame.columns, if you

feel it necessary.

You must not convert any DataFrame to a native data type (e.g. a list or dict) to process

the data.

You must not hard code any file paths within the code you write. These are specified in

the main function, which you must not modify, and are passed as parameters to the

question_X functions that you will complete. You must use these local variables

instead of hard-coded values.

You must not display any plots (e.g. using plt.show), as the code template is configured

to save your plot to disk.

You must not manually edit any datasets. During marking, a copy of the original CSV

and JSON files will be used.

You may import and use any of the Python 3.11 or 3.13 standard libraries. You may not

use any third-party libraries outside of what is provided in the virtual environment

setup.

You may write helper functions in the relevant code template section.

Part 1: Data Ingestion and Cleaning (4 marks)

Question 1: (1 marks)

Load the NSW FuelCheck dataset from the file fuel.csv into a Pandas DataFrame df1.

Handle the CSV input correctly, ensuring that erroneous data does not affect the

structure of the DataFrame.

Hint: Investigate why an extra column appears without any data in the header.

Return the DataFrame as df1.

Output: (60151, 8)

Marking considerations:

[0.5 marks] The data in the DataFrame is correct.

[0.5 marks] The shape of the DataFrame is correct, including the header.

Question 2: (1 marks)

Perform the following on the DataFrame from Question 1 df1, and return a new

DataFrame df2 with the following:

Rename the column header “ServiceStationName” to “Name”.

Ensure the text in the “Suburb” column is all upper case.
Remove any rows for addresses not in NSW.

Output: (59256, 8)

Marking considerations:

[0.5 marks] The above cleaning steps are performed correctly.

[0.5 marks] The remaining data is not malformed in any way.

Question 3: (1 marks)

Load the postcodes dataset from the file postcodes.json into a new Pandas

DataFrame df3. Include all columns except for the “accuracy” column.

Return the DataFrame as df3.

Output: (16875, 6)

Marking considerations:

[0.5 marks] The data in the DataFrame is correct.

[0.5 marks] The header and removal of “accuracy” in the DataFrame is correct.

Question 4: (1 marks)

With the DataFrame df2 as the basis, create a column called “Latitude”, and another

column named “Longitude”. Populate these columns with the corresponding values as

per the postcodes DataFrame df3.

Use the “Postcode” and “PlaceName” fields in fuel.csv to match with postcodes.json.

If there are multiple matches, select the first option after sorting the matches

alphabetically. For example, 2018 is shared by Rosebery and Eastlakes, so Eastlakes

would be selected.

If there are no matches at all, leave the “Latitude” and “Longitude” fields blank.

Save the final DataFrame df4 as a CSV file df4.csv. Do not write the row names (index)

to the CSV file.

Return the final DataFrame as df4.

Output: (59256, 10)

Marking considerations:

[0.5 marks] The data in the DataFrame is correct.

[0.5 marks] The CSV file has the correct data and is named correctly.

Part 2: Data Exploration (2 marks)

Question 5: (2 marks)

Using the data in df4, create a new DataFrame df5, which will provide a summary of the

average fuel price per postcode and fuel type.

df5 should have a hierarchical index, where “Postcode” is the primary index and

“FuelType” is the secondary index.

The DataFrame should include the following:

Index: Postcode

Index: FuelType

Column: AveragePrice

Return the final DataFrame as df5.

Output: (2584, 1)

Example:

Postcode FuelType AveragePrice

2088 E10 123.45

PDL 234.56

ULP91 345.67



2090 E10 456.78

PDL 0.00

ULP91 567.89

The postcodes should be sorted numerically, and the “FuelType” sorted alphabetically

within each postcode.

The final "AveragePrice" for each postcode and fuel type can be found by calculating:

The average per-station and per-type daily fuel price, where there may be

multiple fuel readings per day for a particular fuel type and service station, which

are now aggregated to the service station level.

The average per-postcode and per-type daily fuel price, where the daily averages

for each service station and fuel type are now aggregated to the postcode level.

The final average per-postcode and per-type fuel price, where the daily averages

for each postcode and fuel type are now aggregated to a single value covering

the duration of the dataset.

If there are days without a calculated value for a particular fuel type and postcode,

exclude those from your final calculation.

In the final DataFrame df5, all “FuelType”s should be returned for each postcode, even

if that fuel is not sold in that postcode. The “AveragePrice” in that case would be 0.00.

Note that the “AveragePrice” should be calculated to 2 decimal places (2 d.p.). In this

case, 2 d.p. must always include all digits, even if they are .00.

Marking considerations:

[0.25 marks] The columns have the correct headers

[0.25 marks] The columns are sorted as requested.

[0.5 marks] The indexes are correct.

[1 mark] The “AveragePrice” calculation is correct and rounded to 2 d.p.

Part 3: Data Manipulation (2 marks)

Question 6: (1 marks)

Using the DataFrame df4 as the basis, create a column called “PriceChangeAverage”.

Populate the column with a 2 decimal place (2 d.p.) percentage difference of that row’s

fuel price with the corresponding average fuel price from df5. Note that in this case, 2

d.p. must always include all digits, even if they are .00.

Return the final DataFrame as df6.

Output: (59256, 11)

Example:

Assuming the following row in the previous question from df5:

2088, PDL, 234.56

Assuming your data in df4 contains the following row (some columns omitted for

example’s sake):

BP Mosman (9542),2088,PDL,207.9

Your df6 value for the “PriceChangeAverage” column would be -11.37.

Marking considerations:

[0.25 marks] The column is added correctly.

[0.25 marks] The sign (-/+) and decimal places are correct.
[0.5 marks] The calculated “PriceChangeAverage” values are correct.

Question 7: (1 marks)

Using the DataFrame df6 as the basis, create a column called “PriceChangePrevious”.

Populate the column with the 2 d.p. difference of that row’s fuel price, with the previous

timestamp entry for that exact same fuel type and address. For the first row per unique

service station and fuel type in the DataFrame, set the field as zero. Note that 2 d.p.

must always include all digits, even if they are .00.

Return the final DataFrame as df7.

Output: (59256, 12)

Example:

Assuming your data in df6 contains the following row (some columns omitted for

example’s sake):

Astron Grafton,"105 BENT ST, SOUTH GRAFTON NSW 2460",SOUTH

GRAFTON,2460,ASTRON,P98,2025-01-01 09:09:09,184.9

Astron Grafton,"105 BENT ST, SOUTH GRAFTON NSW 2460",SOUTH

GRAFTON,2460,ASTRON,P98,2025-01-01 10:09:09,188.9

Your df7 value for the “PriceChangePrevious” column would be 4.00.

Marking considerations:

[0.25 marks] The column is added correctly.

[0.25 marks] The sign (-/+) and decimal places are correct.

[0.5 marks] The calculated “PriceChangePrevious” values are correct.

Part 4: Data Visualisation (7 marks)

In this section, the most effective visualisations provide deep insights into the dataset.

You should also aim to achieve:

Suitable choice of visualisation.

Appropriate use of scale and colour.

Appropriate inclusion of title, labels, legend, with suitable sizing.

Visualisation is self-explanatory and informative.

Image is correctly saved to disk, rather than shown.

Question 8: (3.5 marks)

Using the DataFrame df7, create a visualisation to answer the question: “Is it cheaper

to patron independent or franchised service stations?”

Save your visualisation as a PNG file (already setup in the code template) and explain

in a return variable answer8 what insights you have uncovered from this visualisation.

Note: you may use the “Brand” column to distinguish between Independent and all

other (Franchised) service stations.

Marking considerations:

[1.5 marks] The visualisation provides deep insights into the research question.

[1 mark] The visualisation is error free and of professional standard.

[1 mark] The discussion has thorough and sound reasoning explaining how the

visualisation answers the research question.

Question 9: (3.5 marks)

Using the DataFrame df7, create a visualisation to answer the question: “Are

consumers in certain regions of NSW being unfairly charged for fuel compared to other

regions?”

Save your visualisation as a PNG file (already setup in the code template) and explain

in a return variable answer9 what insights you have uncovered from this visualisation.

Marking considerations:

[1.5 marks] The visualisation provides deep insights into the research question.

[1 mark] The visualisation is error free and of professional standard.

[1 mark] The discussion has thorough and sound reasoning explaining how the

visualisation answers the research question.

热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图