python - 在数据框的循环中在空列中添加值的正确方法,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
和列中并使列不可触及?a
one
two
df
three
谢谢你
解决方案
我认为您正在寻找类似的东西:
for i in range(1):
df.loc[i,['one','two']]=['adress','a']
print(df)
one two three
0 adress a NaN
推荐阅读
- java - 更改 JSON 数组对象的顺序
- c++ - 构建错误:“找不到文件的目标”和“未定义的引用”
- javascript - 为什么分页不起作用?
- javascript - 将 svg 转换为 png 时删除默认空间
- java - 在 Java 10 上运行 JProfiler(用于 4K 屏幕)
- events - 完整日历 eventClick 不刷新和堆叠点击
- angular - 订阅未在 Observable.create 对象上触发
- c - extern 如何在 C 中工作,内部函数
- git - 将 Git 存储库中的更改合并到 TFVC 分支
- python - 将 numpy 变量转换为 tf 变量以用于图形冻结