python - 向现有行添加值 -DataFrame
问题描述
我正在将一些天气数据(来自 json-dict) - 用日语附加到 DataFrame 中。
我想要这样的东西
天気 風
0 状態: Clouds 風速: 2.1m
1 NaN 向き: 230
但我有这个
天気 風
0 状態: Clouds NaN
1 NaN 風速: 2.1m
2 NaN 向き: 230
我怎样才能更改代码以使其成为那样?这是代码
df = pd.DataFrame(columns=['天気','風'])
df = df.append({'天気': weather_status}, ignore_index=True) # 状態: Clouds - value
df = df.append({'風': wind_speed}, ignore_index=True) # 風速: 2.1m -value
df = df.append({'風': wind_deg}, ignore_index=True) # 向き: 230 -value
print(df)
解决方案
一种方法可能是:
df = pd.DataFrame(columns=['天気','風'])
df = df.append({'天気': weather_status, '風': wind_speed}, ignore_index=True)
df = df.append({'風': wind_deg}, ignore_index=True)
print(df)
并且不带索引打印
print(df.to_string(index=False))
推荐阅读
- python - How to Change the column width of the tree view in odoo 13?
- matlab - 如何使用 Tihkonov 正则化在 matlab 中对噪声图像进行去噪?
- python - 使用 FlaskLDAP3Login 进行单点登录时是否仍需要表单/登录?
- c# - 更改 a 的可见性
- 真/假 C# 母版页
- reactjs - 使用 alert 打印文本以外的其他内容
- visual-studio - Intellisense 在 Visual Studio for Sql Server 数据项目中不起作用
- python - ImportError:无法从部分初始化的模块“dogehouse”导入名称“DogeClient”(很可能是由于循环导入)
- c# - 逐行发送,不重复
- python - Windows OS下Nodejs运行python脚本
- javascript - 如何将 MapQuest RouteLayer 添加到传单图层