Question

#Python I have a data frame called data_tweets, there is one column calls timestamp, the dataset looks like: 2016-06-25...

#Python

I have a data frame called data_tweets, there is one column calls timestamp, the dataset looks like: 2016-06-25 23:59:52

And there is another data frame called data_BTUSD, the time column looks like:27/5/19 0:00

How can I make these two datafram's time in the same format and draw the time line for them?

Thanks!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Now first you have to extract the column timestamp from data frame data_tweets in a vector time1 and then you have to extract the column time from data frame data_BTUSD in a vector time2 now use the below program to convert time1 values to time2 and then draw a timeline for them:

PYTHON CODE:

def compare(t1,t2):
    if t1[1]=='/':
        day1=int(t1[0])
        if t1[3]=='/':
            month1=int(t1[2])
            year1=int(t1[4:6])
        else:
            month1=int(t1[2:4])
            year1=int(t1[5:7])
    else:
        day1=int(t1[0:2])
        if t1[4]=='/':
            month1=int(t1[3])
            year1=int(t1[5:7])
        else:
            month1=int(t1[3:5])
            year1=int(t1[6:8])
    if t2[1]=='/':
        day2=int(t2[0])
        if t2[3]=='/':
            month2=int(t2[2])
            year2=int(t2[4:6])
        else:
            month2=int(t2[2:4])
            year2=int(t2[5:7])
    else:
        day2=int(t2[0:2])
        if t2[4]=='/':
            month2=int(t2[3])
            year2=int(t2[5:7])
        else:
            month2=int(t2[3:5])
            year2=int(t2[6:8])
    ind1=0
    ind2=0
    for i in range(0,len(t1)):
        if t1[i]==' ':
            ind1=i
            break
    for i in range(0,len(t2)):
        if t2[i]==' ':
            ind2=i
            break
    if t1[ind1+2]==':':
        hour1=int(t1[ind1+1])
        minute1=int(t1[ind1+3:ind1+5])
    else:
        hour1=int(t1[ind1+1:ind1+3])
        minute1=int(t1[ind1+4:ind1+6])
    if t2[ind2+2]==':':
        hour2=int(t2[ind2+1])
        minute2=int(t2[ind2+3:ind2+5])
    else:
        hour2=int(t2[ind2+1:ind2+3])
        minute2=int(t2[ind2+4:ind2+6])
    if year1>year2:
        return 1
    elif year1<year2:
        return 0
    else:
        if month1>month2:
            return 1
        elif month1<month2:
            return 0
        else:
            if day1>day2:
                return 1
            elif day1<day2:
                return 0
            else:
                if hour1>hour2:
                    return 1
                elif hour1<hour2:
                    return 0
                else:
                    if minute1>minute2:
                        return 1
                    elif minute1<minute2:
                        return 0
                    else:
                        return 1
#5 values in time1
time1=['2016-06-25 23:59:52','2018-07-30 00;46:12','2019-05-27 06:00:19','2019-05-27 15:11:26','2020-11-21 01:00:11']
#5 values in time2
time2=['27/5/19 0:00','27/5/19 13:13','28/5/19 4:50','30/7/18 0:45','30/7/19 7:34']
for i in time1:
    t=""
    t+=i[8:10]
    t+='/'
    if i[5]=='0':
        t+=i[6]
    else:
        t+=i[5:7]
    t+='/'
    t+=i[2:4]
    t+=' '
    if i[11]=='0':
        t+=i[12]
    else:
        t+=i[11:13]
    t+=":"
    t+=i[14:16]
    time2.append(t)
print("TIME1 values appended in TIME2")
print(time2)
for i in range(0,len(time2)):
    for j in range(i+1,len(time2)):
        if compare(time2[i],time2[j]):
            time2[i],time2[j]=time2[j],time2[i]
print("Drawing Timeline: ")
for i in time2:
    print(i)

Output:

Run test9 Aahi ah Shr ycharmProjects Scripts\venv\Scripts\python.exe C:/Users/Ashish Shrivastav/PycharmProjects/Scripts/tes

Add a comment
Know the answer?
Add Answer to:
#Python I have a data frame called data_tweets, there is one column calls timestamp, the dataset looks like: 2016-06-25...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • #Python I have a data frame called data_tweets, there is one column calls timestamp, the dataset...

    #Python I have a data frame called data_tweets, there is one column calls timestamp, the dataset looks like: 2016-06-25 23:59:52 And there is another data frame called data_BTUSD, the time column looks like:27/5/19 0:00 How can I make these two datafram's time in the same format and draw the time line for them? Thanks!

  • # python I have a data frame with a column of time stamp, and there are...

    # python I have a data frame with a column of time stamp, and there are many rows in it, the time format looks like this:2016-06-25 23:59:52 How can I change this into:2016-06-25 23:00:00, which means remove all the minutes and seconds, only preserved data and hours

  • Python question: the time is from 2016-01-01 ~ 2018-12-31 such as the columns "Month", "Day", "Year"...

    Python question: the time is from 2016-01-01 ~ 2018-12-31 such as the columns "Month", "Day", "Year" I need to count how many rows data for each day, and each Borough, such as the column "Borough". The Borough includes: QUEENS, BROOKLYN, BRONX, MANHATTAN, STATEN ISLAND, all together is 5 different Boroughs. Many Thanks! Unnamed: 0 Created Date Incident Zip Complaint Type Descriptor Community Board Borough Latitude Longitude Month Day Year 0 19661 01/01/2016 01:00:00 PM 10309.0 Missed Collection (All Materials) 2R...

  • Santa Monica College CS 20A: Data Structures with C++ Spring 2019 Name: True/False: Circle one Assignment...

    Santa Monica College CS 20A: Data Structures with C++ Spring 2019 Name: True/False: Circle one Assignment 1 ID: 1. True / False 2. True / False 3. True / False 4. True / False 5. True / False 6. True / False 7. True / False 8. True / False 9. True / False 10. True / False Variable and functions identifiers can only begin with alphabet and digit. Compile time array sizes can be non-constant variables. Compile time array...

  • Hi it's python I imported a data which are so many words in txt and I arranged and reshaped with ...

    Hi it's python I imported a data which are so many words in txt and I arranged and reshaped with alphabetically both rows and columns I was successful with these steps but I am stuck with next step below is my code and screenshot import numpy as np import pandas as pd data=pd.read_csv("/Users/superman/Downloads/words_file2.txt",header=None) df_input=pd.DataFrame(data) df_output=pd.DataFrame(np.arange(676).reshape((26,26)), index = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'], columns = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']) df_output.index.name="Start" df_output.columns.name="End" df_output This below screen shot is what I have to find I have to find each word...

  • Could anyone help add to my python code? I now need to calculate the mean and...

    Could anyone help add to my python code? I now need to calculate the mean and median. In this programming assignment you are to extend the program you wrote for Number Stats to determine the median and mode of the numbers read from the file. You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The...

  • Complete function long_list_printer.print_list(). When it's finished, it should be able to print this list, a =...

    Complete function long_list_printer.print_list(). When it's finished, it should be able to print this list, a = [ [93, 80, 99, 72, 86, 84, 85, 41, 69, 31], [15, 37, 58, 59, 98, 40, 63, 84, 87, 15], [48, 50, 43, 68, 69, 43, 46, 83, 11, 50], [52, 49, 87, 77, 39, 21, 84, 13, 27, 82], [64, 49, 12, 42, 24, 54, 43, 69, 62, 44], [54, 90, 67, 43, 72, 17, 22, 83, 28, 68], [18, 12, 10,...

  • PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please...

    PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please so I can understand LinkedList ADT: class myLinkedList:     def __init__(self):         self.__head = None         self.__tail = None         self.__size = 0     def insert(self, i, data):         if self.isEmpty():             self.__head = listNode(data)             self.__tail = self.__head         elif i <= 0:             self.__head = listNode(data, self.__head)         elif i >= self.__size:             self.__tail.setNext(listNode(data))             self.__tail = self.__tail.getNext()         else:             current = self.__getIthNode(i - 1)             current.setNext(listNode(data,...

  • PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment...

    PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment the lines please so I can understand. There are short and med files lengths for each the list of names/ids and then search id file. These are the input files: https://codeshare.io/aVQd46 https://codeshare.io/5M3XnR https://codeshare.io/2W684E https://codeshare.io/5RJwZ4 LinkedList ADT to store student records(code is below). Using LinkedList ADT instead of the Python List. You will need to use the Student ADT(code is below) Imports the Student class...

  • Help with Data Science python notebook, Question 1 Create a function called vowel_parse() that takes a...

    Help with Data Science python notebook, Question 1 Create a function called vowel_parse() that takes a single string as input. This string is the name of the input directory. It returns a dictionary. This dictionary has keys that are the names of the individual input files. The dictionary values are the number of words in that file that have adjacent vowels ('aa', 'ae', 'oo', 'ia', etc.). Use a regular expression to find these, do not hard code every possible combination...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT