将变量放入特定位置 [行,列] Pandas Python

Place Variable into a Specific Location [row,column] Pandas Python

我一直在努力将字符串变量 "revenue" 放入 pandas 数据帧 df1。如您所见,我使用了 df.ait.

有关代码的更多详细信息:它是关于通过 m 计数循环查找特定日期行。

我的问题发生在 .iat

if info[1] == "1": #Get Kikko1
    listofdates = df.Date.tolist() 
    m = 0
    for i in listofdates:
        if i != date: #Counting the rows
            m = m+1
        elif i == date: #Select the row with the matched date
            df.iat[m, 9] = "revenue"
            break

错误说:

IndexError: index 36 is out of bounds for axis 0 with size 31

使用像 pandas 这样的包的主要好处之一是避免这种手动循环,这很难遵循和修改。

我认为你可以在一行中完成你需要做的事情。类似于:

df1.loc[date, 9] = 'revenue'

如果这不起作用,您能否在您的问题中编辑一些示例数据和您想要的输出?