Pandas TypeError: an integer is required (got type Timestamp) - Fix for Timestamp Conversion
The error 'TypeError: an integer is required (got type Timestamp)' typically occurs when trying to convert a pandas Timestamp object to a Unix timestamp using the fromtimestamp() method within a lambda function. This is unnecessary, as the pd.to_datetime() method already handles the conversion from Unix timestamp to pandas Timestamp.
To fix the issue, simply remove the unnecessary lambda function and directly use the output of pd.to_datetime() for setting the index:pythondf[' Timestamp'] = pd.to_datetime(df[' Timestamp'], unit='s')df.set_index(' Timestamp', inplace=True)
This will correctly set the ' Timestamp' column as the index of your DataFrame without encountering the TypeError.
原文地址: https://www.cveoy.top/t/topic/nztk 著作权归作者所有。请勿转载和采集!