date

Convert custom string date to date

Convert custom string date to date Question: Is there a way to convert a string date that is stored in some non-traditional custom manner into a date using datetime (or something equivalent)? The dates I am dealing with are S3 partitions that look like this: year=2023/month=2/dayofmonth=3 I can accomplish this with several replaces but im …

Total answers: 2

Polars YYYY week into a date

Polars YYYY week into a date Question: Does anyone know how to parse YYYY Week into a date column in Polars? I have tried this code but it throws an error. Thx import polars as pl pl.DataFrame( { "week": [201901, 201902, 201903, 201942, 201943, 201944] }).with_columns(pl.col(‘week’).cast(pl.Utf8).str.strptime(pl.Date, fmt=’%Y%U’).alias("date")) Asked By: Frank || Source Answers: This seems …

Total answers: 2

python pandas resample monthly aggregated data to daily, then aggregate back to weekly

python pandas resample monthly aggregated data to daily, then aggregate back to weekly Question: Here is my example data: team sales month a 100 1/1/2023 a 200 2/1/2023 b 600 1/1/2023 b 300 2/1/2023 load in pandas like so: mydata = pd.DataFrame([ [‘team’,’sales’,’month’], [‘a’, 100, ‘1/1/2023’], [‘a’, 200, ‘2/1/2023’], [‘b’, 600, ‘1/1/2023’], [‘b’, 300, ‘2/1/2023’] …

Total answers: 1

How to validate if a date indicated as a string belongs to an interval of 2 dates indicated in another string?

How to validate if a date indicated as a string belongs to an interval of 2 dates indicated in another string? Question: import os, datetime content = os.listdir("when") print(content) #this print… #[‘2022_-_12_-_29 12pp33 am _–_ 2023_-_01_-_25 19pp13 pm.txt’, ‘2023-02-05 00pp00 am.txt’] for i in range(len(content)): content[i] = content[i].replace("_-_", "-").replace("pp", ":") print(content) #I prepare the input …

Total answers: 1

Compare <class 'pandas._libs.tslibs.timestamps.Timestamp'>, str and datetime64[ns] dates in Python

Compare <class 'pandas._libs.tslibs.timestamps.Timestamp'>, str and datetime64[ns] dates in Python Question: I need to query using dates of various data types, the data and their corresponding data types are listed below: last_month_year: <class ‘str’> ** Used `pd.to_datetime()` and got `<class ‘pandas._libs.tslibs.timestamps.Timestamp’>` format current_month_year: <class ‘str’> df[‘Year_Month’]: object The query: df[(df[‘Year_Month’] == current_month_year) | (df[‘Year_Month’] == last_month_year)] …

Total answers: 1

How to change default rangeselector in plotly python

How to change default rangeselector in plotly python Question: I am using plotly(python) to implement range selector where I’ve created multiple buttons for selecting ranges and I want to show only one month data by default but it showing all data. My code and its output are below what changes should I make? import plotly.graph_objects …

Total answers: 1

How to extract date from datetime column in polars

How to extract date from datetime column in polars Question: I am trying to move from pandas to polars but I am running into the following issue. import polars as pl df = pl.DataFrame( { "integer": [1, 2, 3], "date": [ "2010-01-31T23:00:00+00:00", "2010-02-01T00:00:00+00:00", "2010-02-01T01:00:00+00:00" ] } ) df = df.with_columns( [ pl.col("date").str.strptime(pl.Datetime, fmt="%Y-%m-%dT%H:%M:%S%z").dt.with_time_zone("Europe/Amsterdam"), ] ) …

Total answers: 2

Convert YYYY-MM-DD to DD-MMM-YYYY in Python

Convert YYYY-MM-DD to DD-MMM-YYYY in Python Question: I’m trying to convert a list of dates (strings) in the format 2023-01-19 into the format 19-Jan-2023. The code I currently have does not work: date_list = [‘2023-01-19’, ‘2023-01-07’, ‘2022-11-29’] new_date_list = [] for date in date_list: date_new_format = datetime.datetime(date, ‘%dd-%mmm-%yyyy’) new_date_list.append(date_new_format) Asked By: Greg || Source Answers: …

Total answers: 1