Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3 - Pandas dataframes - combine tables Part 3. Return of the Pandas! This part of the HW should be in the hw9_pt2.py file.

Python 3 - Pandas dataframes - combine tables

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Part 3. Return of the Pandas! This part of the HW should be in the hw9_pt2.py file. It will be run through the command "python hw9.pt2.". Your code should work as a script, not as a function, to account for this situation You are given two .csv files that contain slightly different tables. You will have to create a new table with certain conditions: So from these two given tables: data1.csv Day data2.csv Month Tweet 12 Happy New Year Day Year Tweet Hello World I want ice-cream Friends will be friends Done with school Month Year Hour 23 30 12 2013 January 2013 March 2017 May 2017 July 21 30 15 2015 2016 2017 2018 7 Today is my final 23 Summer is about to begin 11 Ocean is still cold 9 12 you should get a new table that looks like this: combined.csv Date 15-Jul-18 Ocean is still cold 12-Dec-17 Done with school 30-Sep-17 Friends will be friends 30-May-17 Summer is about to begin 21-Mar-16 Today is my final 02-Jan-15 Happy New Year 23-Jul-13 I want ice-cream! 02-Jun-13 Hello World Tweet Requirements for the combined table: 1. You can't modify and save data manually. I will provide a different set of tables as a test. 2. The combined table keeps the same Tweets from the original tables 3. Date is represented using datetime object. Do not create these strings as it will involve a lot of concatenations. 4. The combined table is sorted by the "Date" column 5. The combined table is saved as combined.csv and contains only two columns. You have to submit this file along with your hw9.py and hw9_pt2.py files. There are a lot of ways to create this table. I do not want to restrict you but I'd like your code to be as efficient as possible. For example, my solution is 22 lines. If you find yourself typing a lot, then STOP and rethink your approach. You are not required to use everything from the list below. They are just what I found helpful. Important Notes: 1. This is going to be a script, not a function. 2. It must work for these specific file names and table formats. o That means that table 1 will always have a tweet, month, day, year and table 2 will have day, month, year, hour, and tweet. 3. Remove the index with index- False 4. Make sure that the DATE is sorted, not the string that makes up the date. 5. Be careful with uppercase Y vs lowercase y when parsing the year 6. If you write any helper methods, make sure to have a valid docstring and doctests. 7. If you do not save to "combined.csv", you will fail this problem completely. (As in, we've warned you) 8. Make super sure that your pathing is relative. If it isn't, you will fail this problem completely. import numpy as np import pandas as pd from datetime import table1- pd. read_csv('data1.csv') table2 pd.read_csv( 'data2.csv') Part 3. Return of the Pandas! This part of the HW should be in the hw9_pt2.py file. It will be run through the command "python hw9.pt2.". Your code should work as a script, not as a function, to account for this situation You are given two .csv files that contain slightly different tables. You will have to create a new table with certain conditions: So from these two given tables: data1.csv Day data2.csv Month Tweet 12 Happy New Year Day Year Tweet Hello World I want ice-cream Friends will be friends Done with school Month Year Hour 23 30 12 2013 January 2013 March 2017 May 2017 July 21 30 15 2015 2016 2017 2018 7 Today is my final 23 Summer is about to begin 11 Ocean is still cold 9 12 you should get a new table that looks like this: combined.csv Date 15-Jul-18 Ocean is still cold 12-Dec-17 Done with school 30-Sep-17 Friends will be friends 30-May-17 Summer is about to begin 21-Mar-16 Today is my final 02-Jan-15 Happy New Year 23-Jul-13 I want ice-cream! 02-Jun-13 Hello World Tweet Requirements for the combined table: 1. You can't modify and save data manually. I will provide a different set of tables as a test. 2. The combined table keeps the same Tweets from the original tables 3. Date is represented using datetime object. Do not create these strings as it will involve a lot of concatenations. 4. The combined table is sorted by the "Date" column 5. The combined table is saved as combined.csv and contains only two columns. You have to submit this file along with your hw9.py and hw9_pt2.py files. There are a lot of ways to create this table. I do not want to restrict you but I'd like your code to be as efficient as possible. For example, my solution is 22 lines. If you find yourself typing a lot, then STOP and rethink your approach. You are not required to use everything from the list below. They are just what I found helpful. Important Notes: 1. This is going to be a script, not a function. 2. It must work for these specific file names and table formats. o That means that table 1 will always have a tweet, month, day, year and table 2 will have day, month, year, hour, and tweet. 3. Remove the index with index- False 4. Make sure that the DATE is sorted, not the string that makes up the date. 5. Be careful with uppercase Y vs lowercase y when parsing the year 6. If you write any helper methods, make sure to have a valid docstring and doctests. 7. If you do not save to "combined.csv", you will fail this problem completely. (As in, we've warned you) 8. Make super sure that your pathing is relative. If it isn't, you will fail this problem completely. import numpy as np import pandas as pd from datetime import table1- pd. read_csv('data1.csv') table2 pd.read_csv( 'data2.csv')

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems 12th Asian Conference ACIIDS 2020 Phuket Thailand March 23 26 2020 Proceedings

Authors: Pawel Sitek ,Marcin Pietranik ,Marek Krotkiewicz ,Chutimet Srinilta

1st Edition

9811533792, 978-9811533792

More Books

Students also viewed these Databases questions

Question

48: How do early experiences modify the brain?

Answered: 1 week ago