I have a dataset in excel where the datetime column in the order dd-mm-yy hh-mm, but upon importing the dataset on jupyter notebook and putting the data into a dataframe, for some rows the format is changing to yy-mm-dd hh-mm which is why i am having trouble converting it into datetime format on python. I am a beginner and my assignment is due today. idk what to do ๐ฆ
#๐ Datetime format.
21 messages ยท Page 1 of 1 (latest)
@brazen oyster
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
!d datetime.datetime.strftime
datetime.strftime(format)```
Return a string representing the date and time, controlled by an explicit format string. See also [strftime() and strptime() Behavior](https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior) and [`datetime.isoformat()`](https://docs.python.org/3/library/datetime.html#datetime.datetime.isoformat).
Sorry, i did not understand. could you please explain?
As a method called off a datetime object, that object representing a date and time, strftime allows you to specify a format of the time data in the string returned.
I can demonstrate, but give me a moment
A quick reference for Python's strftime formatting directives.
That would be REALLY helpful.
!e py from datetime import datetime now = datetime.now() print(now) print(now.strftime('The month is %B and the year is %Y'))
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | 2024-11-06 04:23:50.450426
002 | The month is November and the year is 2024
There may be equivalent strftime methods or parameters available more specific to what you're doing.
Check the ugd object's methods. I don't use Pandas.
I am still quite unsure what to do but thank you for giving me some direction. i will try a few things and let you know.
There will probably be something in Pandas into which you can pass the dataframe and the strftime string or functionality attached to the dataframe that is called strftime that you can give an sttftime string to.
Adding some more info: The dataset on excel:
Code:
# Loading the Excel file and creating dataframes
file_path=""
ugd = pd.read_excel(file_path, sheet_name = "User Gameplay data", skiprows=3 )
dd = pd.read_excel(file_path, sheet_name = "Deposit Data", skiprows=3)
wd= pd.read_excel(file_path, sheet_name = "Withdrawal Data", skiprows=3)
What am I missing?
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.