date

count the number of values in data frame's column that exist in another data frame's column

count the number of values in data frame's column that exist in another data frame's column Question: I have two data frames: df1: Index Date 0 2016-03-21 20:10:00 1 2016-03-22 21:09:00 2 2016-05-03 17:05:00 df2: Index Date 0 2016-03-21 20:10:00 1 2016-03-21 21:00:00 2 2016-03-22 21:09:00 3 2016-05-03 17:05:00 4 2017-06-01 16:10:00 There’s probably a …

Total answers: 2

How to write dataframe to csv for max date rows only (filter for max date rows)?

How to write dataframe to csv for max date rows only (filter for max date rows)? Question: How do I get the df.to_csv to write only rows with the max asOfDate? So that each symbol below will only one row? import pandas as pd from yahooquery import Ticker symbols = [‘AAPL’,’GOOG’,’MSFT’] #There are 75,000 symbols …

Total answers: 1

Pandas – Dataframe dates subtraction

Pandas – Dataframe dates subtraction Question: I am dealing with a dataframe like this: mydata[‘TS_START’] 0 2022-11-09 00:00:00 1 2022-11-09 00:00:30 2 2022-11-09 00:01:00 3 2022-11-09 00:01:30 4 2022-11-09 00:02:00 … I would like to create a new column where: mydata[‘delta_t’] 0 2022-11-09 00:00:30 – 2022-11-09 00:00:00 1 2022-11-09 00:01:00 – 2022-11-09 00:00:30 2 2022-11-09 …

Total answers: 1

Pandas filter dataframe by time

Pandas filter dataframe by time Question: This is not a duplicate of: filter pandas dataframe by time because the solution offered there doesn’t address the same column type that needs to be filtered. I have the following dataframe: i = pd.date_range(‘2018-04-09′, periods=4, freq=’1D20min’) ts = pd.DataFrame({‘A’: [1, 2, 3, 4], ‘B’:i}) ts[‘date’] = pd.to_datetime(ts[‘B’]).dt.date ts[‘time’] …

Total answers: 1

sum up purchases of current year and month

sum up purchases of current year and month Question: I need to add the purchases of users in a list with the following conditions: "Those customers who have a sum of purchases in the current year of 15,000 or more are entitled to a 20% discount. If they have also spent 3000 or more in …

Total answers: 1

'>' not supported between instances of 'type' and 'datetime.date'

'>' not supported between instances of 'type' and 'datetime.date' Question: I’m creating a CRUD application that displays activities available on or after today; I’m working through the filtering mechanism on displaying these activities, however I’m having a nightmare trying to only show the activities that are on/after today. I’m getting the below error when I …

Total answers: 1

Why are python dates such a mess and what can I do about it?

Why are python dates such a mess and what can I do about it? Question: A common source of errors in my Python codebase are dates. Specifically, the different implementations of dates and datetimes, and how comparisons are handled between them. These are the date types in my codebase import datetime import pandas as pd …

Total answers: 1

Python Substring Regex Extraction

Python Substring Regex Extraction Question: I have the following types of strings: FWI20010112 DC20030405 etc… I need to extract segments of the strings into separate variables like this (example): name: FWI year: 2001 month: 01 day: 12 So, the name segment of the string can vary between 2 or 3 characters, and the following digits …

Total answers: 1

Switching between date formats in Python

Switching between date formats in Python Question: I’m parsing invoice PDF files to JSON and they have field called ‘invoice_date’. In one invoice date can be provided as ’03 Apr 2022′ and in the other one – ‘2022-09-23′, for instance. I want my date to be in ‘YYYY-MM-DD’ format always, like in the second example. …

Total answers: 2