I have problem with getting a specific value from DataFrame object.
- My CVS file looks like:
domain1.com,1.1.1.1,2023-01-01,description 1
domain2.com,2.2.2.2,2023-02-23,,description 2
- Next i read CSV using Pandas and Data Frame object
dataset = pd.read_csv('database\domain\ip.csv', sep = ',', header = None)
#headers
dataset.columns = ['domain', 'ip', 'data', 'ASN']
#format column to datetime format from datetime library
dataset['data'] = pd.to_datetime(dataset['data'], format="%Y-%m-%d")
- Next i want check a specific value if existing in DataFrame
if((dataset["domain"] == 'domain2').any()):
- I want get a data and I want compare this date to another:
a = dataset[dataset["domain"] == 'wp.pl.com']['data']
if (datetime.now() - a) > timedelta(days = 30):
#something
But i got error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
If i change to: a.any()
or a.any()
i got another error:
TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'bool
Anybody know how can i compare two dates?
Try before to get both dates as strings and convert them to objects using
datetime.strptime()
For example: