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
的{{1}}和a
列中添加值one
和two
,并使列df
不可触摸? / p>
谢谢
答案 0 :(得分:1)
我认为您正在寻找类似的东西:
for i in range(1):
df.loc[i,['one','two']]=['adress','a']
print(df)
one two three
0 adress a NaN
答案 1 :(得分:1)
我首先创建一个熊猫系列,其中包含我想要的值和列。例如:
new_values= pd.Series(["a", "b"], index=["one", "two"])
然后我将该系列附加到原始数据框:
df= df.append(new_values, ignore_index=True)