datetime

Loop through a dataframe, using specific values for individual dates

Loop through a dataframe, using specific values for individual dates Question: I have a dataframe that looks like the below. I want to create a new column titled ‘Daily Change’ which will be the result of the first ‘Open’ price of each day divided by the ‘Open’ price for each 5 minute interval. Once the …

Total answers: 1

Nested for loop to create list of urls

Nested for loop to create list of urls Question: I am looking for a way to create a list of urls by modifying the name of the country and the date/time. For each country, each day and each hour of the day I need to create a unique url. import datetime start_date = datetime.date(2019, 4, …

Total answers: 1

Calculating timedeltas across daylight saving

Calculating timedeltas across daylight saving Question: I’m facing a python timezones problem and am unsure of what is the right approach to deal with it. I have to calculate timedeltas from given start and end DateTime objects. It can happen that daylight saving time will change during the runtime of my events, so I have …

Total answers: 1

Pandas find overlapping time intervals in one column based on same date in another column for different rows

Pandas find overlapping time intervals in one column based on same date in another column for different rows Question: I have data that looks like this: id Date Time assigned_pat_loc prior_pat_loc Activity 0 45546325 2/7/2011 4:29:38 EIAB^EIAB^6 NaN Admission 1 45546325 2/7/2011 5:18:22 8W^W844^A EIAB^EIAB^6 Observation 2 45546325 2/7/2011 5:18:22 8W^W844^A EIAB^EIAB^6 Transfer to 8W …

Total answers: 1

datetime conversion of a column results in pandas warning

datetime conversion of a column results in pandas warning Question: I am trying to convert a column in a pandas dataframe to datetime format as follows: df["date"] = pd.to_datetime(df["date"]) Although this works as expected, pandas gives the following warning: A value is trying to be set on a copy of a slice from a DataFrame. …

Total answers: 1

Creating a date range in python-polars with the last days of the months?

Creating a date range in python-polars with the last days of the months? Question: How do I create a date range in Polars (Python API) with only the last days of the months? This is the code I have: pl.date_range(datetime(2022,5,5), datetime(2022,8,10), "1mo", name="dtrange") The result is: ‘2022-05-05’, ‘2022-06-05’, ‘2022-07-05’, ‘2022-08-05’ I would like to get: …

Total answers: 2

Converting a numpy float array to datetime array

Converting a numpy float array to datetime array Question: I have a data in which the time are recorded as digits in each columns of a numpy array (dtype= float64) as shown here. year month day hour 2013 12 3 8.3478 2013 12 3 8.3480 2013 12 3 8.3482 2013 12 3 8.3488 2013 12 …

Total answers: 1

How to remove the elements in a specified period, from a Datetime indexed array

How to remove the elements in a specified period, from a Datetime indexed array Question: I have an array with DateTime index. For example: import scipy.stats as st import pandas as pd n = 50000 dur = st.expon.rvs(loc=0, scale=1, size=n) sgn = st.norm.rvs(0,1, size=n) t = dur.cumsum() df = pd.DataFrame({‘Date_Time’:t,’sgn’:sgn}) df[‘Date_Time’]=pd.to_datetime(df.Date_Time, unit=’s’) df=df.set_index([‘Date_Time’]) I want …

Total answers: 1

Create new column by comparing existing column in a DataFrame

Create new column by comparing existing column in a DataFrame Question: I have the following DataFrame: datetime day_fetched col_a col_b 0 2023-01-02 12:00:00 2023-01-01 12:00:00 100 200 1 2023-01-02 12:00:00 2023-01-02 12:00:00 120 400 2 2023-01-03 12:00:00 2023-01-02 12:00:00 140 500 3 2023-01-03 12:00:00 2023-01-03 12:00:00 160 700 4 2023-01-04 12:00:00 2023-01-03 12:00:00 200 300 …

Total answers: 1