Reputation: 51
I am trying to delete the 00:00:00(HH:MM:SS) from my link using pandas.
https://www.z-ratos.com/orical/?from=USD&amount=0&date=2018-10-24 00:00:00
So How I delete this 00:00:00 from my link so that its working properly. I tried this code:
import requests
import pandas as pd
from datetime import *
# TO TAKE DATE DIFFERENCE IN LIST
today = datetime.today()
dates = pd.date_range('2018-10-13', today)
#print(dates)
for i in dates:
#print(i)
url = 'https://www.z-ratos.com/orical/?from=USD&amount=0&date%s'%i
print(url)
Comming output is:
https://www.z-ratos.com/orical/?from=USD&amount=0&date=2018-10-24 00:00:00
.....
......
......
Required Output is:
https://www.z-ratos.com/orical/?from=USD&amount=0&date=2018-10-24
So please help thanks in Advance...
Upvotes: 0
Views: 1993
Reputation: 862661
Use DatetimeIndex.strftime
for strings:
dates = pd.date_range('2018-10-13', today).strftime('%Y-%m-%d')
And then format
or f-strings
:
for i in dates:
#print(i)
url = 'https://www.z-ratos.com/orical/?from=USD&amount=0&date={}'.format(i)
#python 3.6+ solution
#url = f'https://www.z-ratos.com/orical/?from=USD&amount=0&date={i}'
print(url)
Upvotes: 3
Reputation: 1435
Use the date
method of a Datetime
object. To remove the timestamp from all your dates:
dates = [d.date() for d in dates]
Alternatively just use i.date()
when you iterate through the dates.
Upvotes: 1
Reputation: 82765
Use strftime("%Y-%m-%d")
Ex:
import requests
import pandas as pd
from datetime import *
# TO TAKE DATE DIFFERENCE IN LIST
today = datetime.today()
dates = pd.date_range('2018-10-13', today)
#print(dates)
for i in dates:
#print(i)
url = 'https://www.z-ratos.com/orical/?from=USD&amount=0&date%s'%i.strftime("%Y-%m-%d")
print(url)
Upvotes: 6