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

Tyl*_*wan 4 python attributes pandas

以下代码片段工作正常,直到我添加了几行引用日期但不在其上方追加或更改它的代码行.简单的设置案例

date = ['1/1/2001','1/1/2001','1/1/2001','1/1/2001']
Run Code Online (Sandbox Code Playgroud)

代码

 import pandas as pd
 ProdDate = ['1/1/2001','1/1/2001','1/1/2001','1/1/2001']
 df = pd.DataFrame(ProdDate, columns = ['Date'])
Run Code Online (Sandbox Code Playgroud)

工作良好.这就是为什么这令人困惑,因为现在date是一个250000值的列表,直到我在上面添加了几行代码并且现在这行返回时才一直没用

AttributeError: 'str' object has no attribute 'DataFrame' 
Run Code Online (Sandbox Code Playgroud)

无论我做什么,我似乎无法在简单的情况下复制.

编辑

几行代码

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]
Run Code Online (Sandbox Code Playgroud)

Kar*_*tel 8

错误意味着它的内容:

AttributeError: 'str' object has no attribute 'DataFrame' 
      ^           ^                                ^
the kind of error |                                |
       the thing you tried to use      what was missing from it
Run Code Online (Sandbox Code Playgroud)

它抱怨的线:

df = pd.DataFrame(date, columns = ['Date'])
     ^      ^
     |   the attribute the error said was missing
the thing the error said was a string
Run Code Online (Sandbox Code Playgroud)

在我上面添加几行代码之前,一直没有问题

显然,在"上面几行代码"中的某个地方,你导致pd了一个字符串.当然,当我们查看这几行代码时,我们会发现:

pd = PDays[j]
^       ^
|    the string that you're making it into
the thing that you're making a string
Run Code Online (Sandbox Code Playgroud)