'numpy.int64' object has no attribute 'translate'
时间: 2023-09-21 12:11:27 浏览: 153
It seems like you are trying to use the `translate` function on a `numpy.int64` object, which is not supported. The `translate` function is available for string objects in Python, but it cannot be used directly on numerical types like `int64`.
If you want to perform some translation operation on the numerical value represented by `numpy.int64`, you will first need to convert it to a string before using the `translate` function.
Here's an example of how you can convert the `numpy.int64` object to a string and then apply the `translate` function:
```python
import numpy as np
# Example numpy.int64 object
num = np.int64(12345)
# Convert to string
num_str = str(num)
# Use translate function on the string
translated_str = num_str.translate({ord('1'): 'A', ord('2'): 'B', ord('3'): 'C'})
print(translated_str)
```
This will output the translated string based on the provided translation dictionary. Feel free to modify the translation dictionary (`{ord('1'): 'A', ord('2'): 'B', ord('3'): 'C'}`) according to your requirements.
阅读全文