下面的代碼片段工作正常,直到我添加了幾行代碼引用日期但不追加或更改它之上。與設置Python AttributeError:'str'對象沒有屬性'DataFrame'
date = ['1/1/2001','1/1/2001','1/1/2001','1/1/2001']
代碼的簡單情況
import pandas as pd
ProdDate = ['1/1/2001','1/1/2001','1/1/2001','1/1/2001']
df = pd.DataFrame(ProdDate, columns = ['Date'])
工作正常。這就是爲什麼這是混亂的,因爲現在的日期是,直到我說上面的幾行代碼已經工作沒有問題250000個值的列表,現在這條線返回
AttributeError: 'str' object has no attribute 'DataFrame'
我不能似乎在複製不管我做什麼都簡單的情況。
編輯
的代碼的幾行
for i in range(0,len(UniqueAPI)):
for j in range(0,len(API)):
if UniqueAPI[i] == API[j]:
index = j
pd = PDays[j]
g = vG[j]
o = vO[j]
c = vC[j]
lhs, rhs = str(ProdDate[j]).rsplit("/", 1)
daycounter = 0
start = 365 - int(pd)
if clndr.isleap(int(rhs)):
calDays = LeapDaysInMonth
else:
calDays = DaysInMonth
break
for j in range(0,12):
daycounter = daycounter + DaysInMonth[j]
if daycounter - start >= 0:
m = j
break
for j in range(0,12):
if m == 0:
break
if j < m:
Liq[index+j] = 0
Gas[index+j] = 0
else:
if clndr.isleap(int(rhs)):
days = 366
Gas[index+j] = (g/days)*LeapDaysInMonth[j]
Liq[index+j] = (o/days)*LeapDaysInMonth[j] + (cndval/days)*LeapDaysInMonth[j]
else:
days = 365
Gas[index+j] = (g/days)*DaysInMonth[j]
Liq[index+j] = (o/days)*DaysInMonth[j] + (c/days)*DaysInMonth[j]
「它一直工作,直到我在這上面添加了幾行代碼」;除了您添加的「幾行代碼」之外,您向我們展示了所有內容,這些都是問題的根源。 –
嗯我更curiouse關於如何拋出錯誤及其意義與修復錯誤,但反正附加了代碼。 –
'pd = PDays [j]' - >現在'pd'不再引用'熊貓' – schwobaseggl