无法使用loc在Pandas数据框上保存信息

问题描述

如果有人能解释为什么会发生这种情况,我将非常感谢。

我正在遍历数据框并保存一些我在线收集的信息。如果我使用df.loc [i] ['column'],则该信息不会保存;但是,如果我使用df.column [i],它确实可以! 我以为两种方法都等效,为什么会这样?

这是我的代码

df=pd.read_excel([ADRESS])
df.['CID']='' 

for i in range(df.shape[0]):
  info=[GETTINGDATAONLINE]
  print('all the data')
  print(info)

  if info:
      df.CID[i]=info[0]['CID']
      print('the two following should be the same')
      print(info[0]['CID'])
      print(df.CID[i])

      df.loc[i+1]['CID'] = info[0]['CID']
      print('these two should also be the same')
      print(info[0]['CID'])
      print(df.loc[i+1]['CID'])

这是我在控制台中得到的:

all the data
[{'CID': 5280804,'Synonym': .....]
the two following should be the same
5280804
5280804
these two should also be the same
5280804

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)