|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
打算读取csv数据后,把时间竖列的数值去除最后2位,并代替整列,但运行的时候,出现AttributeError错误,麻烦大家帮忙解决
文件无法上传,发个网盘地址
链接:pan.baidu.com/s/1JmNnddG0UpRJomDca9AX1A?pwd=n9w1
提取码:n9w1
时间
130548490
130548500
130548510
130548510
130548510
130548510
130548510
130548510
130548510
130548510
130548510
130548510
130548510
130548510
130548520
130548520
130548530
130548530
130548610
130551150
130551440
130551500
130551520
130551550
130551580
130552330
130552330
import pandas as pd
import numpy as np
ceshi = pd.read_csv("g:\测试.csv",encoding='gb2312')
ceshi['时间'] = ceshi.时间.str[:-2]
print(ceshi)
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/pythonProject/venv/Scripts/2.py", line 4, in <module>
ceshi['时间'] = ceshi.时间.str[:-2]
File "C:\Users\Administrator\PycharmProjects\pythonProject\venv\lib\site-packages\pandas\core\generic.py", line 5902, in __getattr__
return object.__getattribute__(self, name)
File "C:\Users\Administrator\PycharmProjects\pythonProject\venv\lib\site-packages\pandas\core\accessor.py", line 182, in __get__
accessor_obj = self._accessor(obj)
File "C:\Users\Administrator\PycharmProjects\pythonProject\venv\lib\site-packages\pandas\core\strings\accessor.py", line 181, in __init__
self._inferred_dtype = self._validate(data)
File "C:\Users\Administrator\PycharmProjects\pythonProject\venv\lib\site-packages\pandas\core\strings\accessor.py", line 235, in _validate
raise AttributeError("Can only use .str accessor with string values!")
AttributeError: Can only use .str accessor with string values! |
|