hi i had this as a test yesterday and i would like to know if i did any bad mistakes , i could not ask my classmates for their code , so can you please code this one for me please , i did it in 45 mins but i guess a proffessional will have it done in less , thank uuuu and please i want to compare my code to yours. We have a data file that contains data in a number of rows. Each row is expected to be made of 4 items separated by a tab. We need to read the data into a python dictionary list, then do some clean up and plot the data. Write code as detailed below. Your code must follows the specs and restrictions shown below to be valid. 1. In the main function: ask the user for a file name. pass the filename to a function named fileToDict that will return a list of dictionary items. The dictionary received above will be passed to another function cleanUp which returns a cleaned up version of the data. The list received will then be passed to another function named myPlot to create a two-line plot. That function returns the plot to the main function. show the plot then ask the user if they wish to save it, and if so, ask for the filename and save the plot, else we're done. 2. The function to read the data, which should be named fileToDict will receive a file name then reads the data from the file one line at a time. For the sake of this function you are only allowed to import the regular expression module we learned about. No other import is allowed. Using a regex expression, collect the email address, this will be the key. We expect the rest of the data on that line to be a number. If the email is unique, create an entry in the list being created, where the email is the key and the list that follows contain the number we just read from that line. Otherwise, add the number of the current line to the existing value list. For example, if email 'abc' appears in the file twice with numbers 24 and later with 56, the dictionary entry should be 'abc':['24' , '56'] Once all lines have been processed, return the dictionary. If an entry has an invalid email address, then create a key 'invalid@email.com' and add all the numeric entries of the invalid emails to that entry. If an entry has no valid numbers, then use the value 'invalid' as the numeric entry. for example if email 'abc has no valid numeric entry first then later has a valid entry of 7, then it appears as 'abc':['invalid' , '7'] 3. The function cleanUp which receives the dictionary discussed above, will create a new dictionary and returns it as follows: The new dictionary entry will be the same as the received entry if the email and the data list do not contain any entry of 'invalid'. If the email is invalid, then keep that key as is. If any of the data in the list is invalid, change it to '0'. Once the data of the current entry is processed, add all the entries and add the email as the key and the sum as the value. return the dictionary of emails and sums. This is the cleaned data. 4. Once obtains the clean data from the function of the step above , the data will be passed to myPlot which creates a plot as follows: Using matplotlib or pandas plot the data in bars. the x axis is represented by the email addresses, with the tics showing those emails. the y axis is the value of that email. return the plot figure.
hi i had this as a test yesterday and i would like to know if i did any bad mistakes , i could not ask my classmates for their code , so can you please code this one for me please , i did it in 45 mins but i guess a proffessional will have it done in less , thank uuuu and please i want to compare my code to yours.
We have a data file that contains data in a number of rows. Each row is expected to be made of 4 items separated by a tab.
We need to read the data into a python dictionary list, then do some clean up and plot the data. Write code as detailed below.
Your code must follows the specs and restrictions shown below to be valid.
1. In the main function:
- ask the user for a file name.
- pass the filename to a function named fileToDict that will return a list of dictionary items.
- The dictionary received above will be passed to another function cleanUp which returns a cleaned up version of the data.
- The list received will then be passed to another function named myPlot to create a two-line plot. That function returns the plot to the main function.
- show the plot then ask the user if they wish to save it, and if so, ask for the filename and save the plot, else we're done.
2. The function to read the data, which should be named fileToDict will receive a file name then reads the data from the file one line at a time.
- For the sake of this function you are only allowed to import the regular expression module we learned about. No other import is allowed.
- Using a regex expression, collect the email address, this will be the key. We expect the rest of the data on that line to be a number.
- If the email is unique, create an entry in the list being created, where the email is the key and the list that follows contain the number we just read from that line.
- Otherwise, add the number of the current line to the existing value list. For example, if email 'abc' appears in the file twice with numbers 24 and later with 56, the dictionary entry should be 'abc':['24' , '56']
- Once all lines have been processed, return the dictionary.
- If an entry has an invalid email address, then create a key 'invalid@email.com' and add all the numeric entries of the invalid emails to that entry.
- If an entry has no valid numbers, then use the value 'invalid' as the numeric entry. for example if email 'abc has no valid numeric entry first then later has a valid entry of 7, then it appears as 'abc':['invalid' , '7']
3. The function cleanUp which receives the dictionary discussed above, will create a new dictionary and returns it as follows:
- The new dictionary entry will be the same as the received entry if the email and the data list do not contain any entry of 'invalid'.
- If the email is invalid, then keep that key as is.
- If any of the data in the list is invalid, change it to '0'.
- Once the data of the current entry is processed, add all the entries and add the email as the key and the sum as the value.
- return the dictionary of emails and sums. This is the cleaned data.
4. Once obtains the clean data from the function of the step above , the data will be passed to myPlot which creates a plot as follows:
- Using matplotlib or pandas plot the data in bars.
- the x axis is represented by the email addresses, with the tics showing those emails.
- the y axis is the value of that email.
- return the plot figure.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 4 images