Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do i remove part of a key in a python dictionary

I want to only see the times in the dictionary as it it currently being printed like

dictionary

How do i only see, for example the 17:00 – 18:00 part of the dictionary.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

event_dates = {} #dictionary to store event dates and time
df = pd.read_html('https://www.dcu.ie/students/events')[0]['Event date']
event_dates.update(df)

I have tried using the pop method but doesn’t seem to work.
this is how i am printing it

for key in event_dates.values():
     print(key)

>Solution :

IIUC, you want to remove the dates and keep only the time.

You could use a regex:

df = df.str.replace('([a-zA-Z]+ \d+, |\s+(?=\s))', '')

output:

0     09:00 - 17:00
1     12:45 - 14:00
2     17:00 - 18:00
3     13:00 - 14:00
4     13:15 - 13:35
...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading