I have problems with pandas - datatime

I wanted to reach out regarding a small app I developed to monitor my internet speed. Unfortunately, it seems to have stopped functioning after the most recent update, despite working well previously. I suspect that the issue may lie within the following line of code:

df[‘timestamp’] = pd.to_datetime(df[‘timestamp’])

Could you kindly provide any insights or suggestions regarding what might be causing this problem? It’s worth mentioning that the code appears to be running perfectly fine on my computer.

If you have the time, I would greatly appreciate it if you could take a look at the complete project via the following link:

Link to the full project on GitHub

Thank you in advance for your assistance!!

Hi @talchaim! :wave:

Thanks for posting your issue, and welcome to our forums! :raised_hands:

Unfortunately, I cannot see the GitHub file you shared.

I’ve got a 404, so either the link is broken or the link is private.

If the latter is the case, would you mind making it public if possible? Alternatively, I’m happy to share my email address so you can privately share it with me. :blush:

From the line of code you’ve shared, it appears that you’re using Pandas in Python to convert a column named ‘timestamp’ in a DataFrame (df) into a DateTime object. The error could be related to the format of the timestamp you’re trying to convert or the existence of null or NaN values.

Here are a few points to consider:

  1. Incorrect Format: pd.to_datetime() attempts to convert a series of strings into DateTime objects. If the string cannot be parsed into a valid DateTime, an error will be raised. Make sure the ‘timestamp’ data is in a format that Pandas can understand. If the data isn’t in a standard format, you may need to specify the format using the ‘format’ parameter.
  2. Null or NaN Values: pd.to_datetime() will fail if there are any null or NaN values in the ‘timestamp’ column. You can use df['timestamp'].isna().any() to check if there are any such values. If there are, you can drop them with df = df.dropna(subset=['timestamp']) before converting to DateTime.
  3. Data Type: The ‘timestamp’ column should be of a type that can be converted to DateTime, typically a string. If it’s a different type, you may need to convert it first.

If you’ve checked all of the above and the issue persists, sending us the code for further investigation would definitely help. This will give us more insight into what might be going wrong.

I hope this helps.


This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.