Category : datetime

Hello I tried different code to remove AM/MP from csv file in python (pandas). date_time 5/5/2014 7:42:39 AM I used following code but UNFORTUNATELY nothing changes. Could you please let me know how can I get ride of PM/AM from column date in pandas? df[‘TimeStamp’] = pd.to_datetime(df[‘TimeStamp’], format="%m/%d/%Y %I:%M:%S %p") Colud you please let me ..

Read more

I’m trying to plot a date column in plotly express. I’ve converted the source to date as below, grouped[‘date’] = grouped[‘PROC_DT’].dt.date this was done initially as I was using Seaborn to plot, and it showed the full DateTime including nanoseconds etc*) and am plotting with, import plotly.express as px fig = px.bar(grouped, x=’date’, y=’Cum Alloc ..

Read more

I have the following string which includes time and date along with n with numbers. I want only date time value. Input: str1 = ‘1 2016-04-30 00:30:00n2 2016-04-30 02:00:00n3 2016-04-30 02:00:00n4 2016-04-30 03:16:00n5 2016-04-30 08:27:18n6 2016-04-30 10:10:00n7 2016-04-30 10:27:00n8 2016-04-30 13:00:00n9 2016-04-30 14:00:00n10 2016-04-30 16:00:00n11 2016-04-30 16:30:00n12 2016-04-30 16:30:00n13 2016-04-30 17:18:00n14 2016-04-30 19:00:00n15 2016-04-30 19:30:00n16 ..

Read more

Can somebody please explain me the behaviour of the following pydantic model. from datetime import datetime from pydantic import BaseModel first_format = {‘time’: ‘2018-01-05T16:59:33+00:00’,} second_format = {‘time’: ‘2021-03-05T08:21:00.000Z’,} class TimeModel(BaseModel): time: datetime class Config: json_encoders = { datetime: lambda v: v.isoformat(), } json_decoders = { datetime: lambda v: datetime.fromisoformat(v), } print(TimeModel.parse_obj(first_format)) print("first_format successfull") print(TimeModel.parse_obj(second_format)) print("second_format ..

Read more

I have a sample dataframe like as shown below df=pd.DataFrame({‘Adm DateTime’:[’02/25/2012 09:40:00′,’03/05/1996 09:41:00′,’11/12/2010 10:21:21′,’31/05/2012 04:21:31′,’21/07/2019 13:15:02′,’31/10/2020 08:21:00′], ‘s_id’:[1,1,1,1,2,2], ‘t_id’:[‘t1′,’t2′,’t3′,’t3′,’t4′,’t5’]}) df[‘Adm DateTime’] = pd.to_datetime(df[‘Adm DateTime’]) I would like to generate row number based for each group (of s_id) I tried the below df[‘R_N’] = df.sort_values([‘Adm DateTime’], ascending=True).groupby([‘s_id’]).cumcount() + 1 While this works in sample data, it ..

Read more

I want to connect the orange dots to the blue dots. I convert a list of strings to datetimes first_test = [dt.datetime.strptime(date, ‘%m/%d/%Y’).date() for date in first_test] handler_arrive = [dt.datetime.strptime(date, ‘%m/%d/%Y’).date() for date in handler_arrive] Then I plot them: scat1 = ax.scatter(first_test, handlers) scat2 = ax.scatter(handler_arrive, handlers) I tried to connect them by calling: plt.plot_date(first_test, ..

Read more

I need to merge two CSV (one called SF1, the other DAILY) files on their dates and to do so, I need to turn their dates into dateime objects. I do so by: self.daily[‘date’] = pd.to_datetime((self.daily[‘date’])) self.sf1[‘calendardate’] = pd.to_datetime(self.sf1[‘calendardate’]) I merge them with this code: self.complete_data = pd.merge_asof(self.daily, self.sf1, by=’ticker’, left_on=’date’, right_on=’calendardate’) Once they are ..

Read more