首页 > 解决方案 > 在数据框的循环中在空列中添加值的正确方法,python

问题描述

df=pd.DataFrame[columns='one','two','three']

for home in city:
    adres= home
    for a in abc: #abc is pd.Series od names
        #here i want to add values - adress and a , but my dataframe have 3 columns, i will use only 2 here
         df.loc[len(df)]= [adres, a, np.nan]
          print(df)
one, two, three
alabama, flat, NaN

我应该如何将值添加到adres和列中并使列不可触及?aonetwodfthree

谢谢你

标签: pythonpandasdataframe

解决方案


我认为您正在寻找类似的东西:

for i in range(1):
    df.loc[i,['one','two']]=['adress','a']
print(df)

      one two three
0  adress   a   NaN

推荐阅读