AttributeError: 'str' 对象没有属性 'strftime' 面临错误

开发

我在编码时遇到了这个问题;

import pandas as pd
import matplotlib from matplotlib import dates as d
import datetime as dt
import matplotlib.pyplot as plt
import numpy as np
data = pd.read_excel(r'F:\Downloads\Book1.xlsx', index_col=0)
data.replace('NoData', np.nan, inplace= True)
data['Time'] = data.index.map(lambda x: x.strftime("%H:%M"))

错误:

AttributeError: 'str' object has no attribute 'strftime'
亚历克斯·韦古德

您可以parse_datesread_excel()调用中使用参数,这意味着 Pandas 应该将指定的列转换为 datetime 对象:

import pandas as pd
import matplotlib from matplotlib import dates as d
import datetime as dt
import matplotlib.pyplot as plt
import numpy as np
data = pd.read_excel(r'F:\Downloads\Book1.xlsx', index_col=0, parse_dates=[0])
data.replace('NoData', np.nan, inplace= True)
data['Time'] = data.index.map(lambda x: x.strftime("%H:%M"))

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_excel.html

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

AttributeError:修改熊猫数据框时,“ str”对象没有属性“ strftime”

Python错误:AttributeError:'str'对象没有属性'k'

获取 AttributeError 错误“str”对象没有属性“get”

AttributeError: 'str' 对象没有属性 'member' 错误

AttributeError: 'str' 对象没有属性 'text' 错误

AttributeError:'str'对象没有属性'str'

AttributeError: 'datetime.timedelta' 对象没有属性 'strftime'

Python属性错误:AttributeError:'str'对象没有属性'to_csv'

AttributeError:“ str”对象没有属性“ name”

AttributeError:'str'对象没有属性'errno'

AttributeError:'str'对象没有属性'union'

AttributeError: 'str' 对象没有属性 'loc'

AttributeError:“ str”对象没有属性“ ndim”

AttributeError:“ str”对象没有属性“ values”

AttributeError:'str'对象没有属性'xpath'

AttributeError:“ str”对象没有属性“ decode”

AttributeError(“'str'对象没有属性'read'”)

AttributeError(“'str'对象没有属性'read'”)

/'str'对象的AttributeError没有属性'objects'

AttributeError: 'str' 对象没有属性 'fetchone'

AttributeError:'str'对象没有属性'isnumeric'

AttributeError: 'str' 对象没有属性 'client'

AttributeError:'str'对象没有属性'fileno'

AttributeError: 'str' 对象没有属性 'keys'

AttributeError:'str'对象没有属性sleep

attributeError:'str'对象没有属性'dbname'

AttributeError: 'str' 对象没有属性 'map'

AttributeError:'str'对象没有属性'author'

AttributeError: 'str' 对象没有属性 'mode'