নির্দিষ্ট টাইমস্ট্যাম্প তুলনা করতে, বর্গাকার বন্ধনীতে সূচক নম্বর ব্যবহার করুন। প্রথমে, প্রয়োজনীয় লাইব্রেরি আমদানি করুন -
import pandas as pd
3টি কলাম সহ একটি ডেটাফ্রেম তৈরি করুন। আমাদের টাইমস্ট্যাম্প সহ দুটি তারিখ কলাম আছে −
dataFrame = pd.DataFrame( { "Car": ["Audi", "Lexus", "Tesla", "Mercedes", "BMW"], "Date_of_Purchase": [ pd.Timestamp("2021-06-10"), pd.Timestamp("2021-07-11"), pd.Timestamp("2021-06-25"), pd.Timestamp("2021-06-29"), pd.Timestamp("2021-03-20"), ], "Date_of_Service": [ pd.Timestamp("2021-11-05"), pd.Timestamp("2021-12-03"), pd.Timestamp("2021-10-30"), pd.Timestamp("2021-11-29"), pd.Timestamp("2021-08-20"), ] })
নির্দিষ্ট টাইমস্ট্যাম্প খুঁজুন, ধরা যাক 1 থেকে 3 সারি −
timestamp1_diff = abs(dataFrame['Date_of_Purchase'][0]-dataFrame['Date_of_Service'][0]) timestamp2_diff = abs(dataFrame['Date_of_Purchase'][1]-dataFrame['Date_of_Service'][1]) timestamp3_diff = abs(dataFrame['Date_of_Purchase'][2]-dataFrame['Date_of_Service'][2])
উদাহরণ
নিম্নলিখিত কোড -
import pandas as pd # create a dataframe with 3 columns dataFrame = pd.DataFrame( { "Car": ["Audi", "Lexus", "Tesla", "Mercedes", "BMW"], "Date_of_Purchase": [ pd.Timestamp("2021-06-10"), pd.Timestamp("2021-07-11"), pd.Timestamp("2021-06-25"), pd.Timestamp("2021-06-29"), pd.Timestamp("2021-03-20"), ], "Date_of_Service": [ pd.Timestamp("2021-11-05"), pd.Timestamp("2021-12-03"), pd.Timestamp("2021-10-30"), pd.Timestamp("2021-11-29"), pd.Timestamp("2021-08-20"), ] }) print"DataFrame...\n", dataFrame # compare specific timestamps timestamp1_diff = abs(dataFrame['Date_of_Purchase'][0]-dataFrame['Date_of_Service'][0]) timestamp2_diff = abs(dataFrame['Date_of_Purchase'][1]-dataFrame['Date_of_Service'][1]) timestamp3_diff = abs(dataFrame['Date_of_Purchase'][2]-dataFrame['Date_of_Service'][2]) print"\nDifference between Car 1 Date of Purchase and Service \n",timestamp1_diff print"\nDifference between Car 2 Date of Purchase and Service \n",timestamp2_diff print"\nDifference between Car 3 Date of Purchase and Service \n",timestamp3_diff
আউটপুট
এটি নিম্নলিখিত আউটপুট −
তৈরি করবেDataFrame... Car Date_of_Purchase Date_of_Service 0 Audi 2021-06-10 2021-11-05 1 Lexus 2021-07-11 2021-12-03 2 Tesla 2021-06-25 2021-10-30 3 Mercedes 2021-06-29 2021-11-29 4 BMW 2021-03-20 2021-08-20 Difference between Car 1 Date of Purchase and Service 148 days 00:00:00 Difference between Car 2 Date of Purchase and Service 145 days 00:00:00 Difference between Car 3 Date of Purchase and Service 127 days 00:00:00