python - 修改字典中的数据框
问题描述
我有一个像这样的数据框字典:
variables = [x, y, z, t]
dictionary_of_dataframes = {'df1':pd.DataFrame(data1, columns =variables),'df2' : pd.DataFrame(data2, columns =variables),'df3' : pd.DataFrame(data3, columns =variables)}
我正在尝试将存储在变量中的一些数据转换为数字。
for elem in dictionary_of_logs:
elem[['x','y']].apply(pd.to_numeric)
但它返回我TypeError: string indices must be integers
。有可能这样循环吗?
解决方案
如果你在 dict 中使用 for,你只会得到键。如果要迭代值,请使用:
for elem in dictionary_of_logs.values():
elem[['x','y']].apply(pd.to_numeric)
推荐阅读
- jwt - JWE nimbus-JOSE 真实性和 JavaScript 对应物
- javascript - 在 React 中使用 useReducer 和 useContext 的正确方法
- r - 将均值和 SD 添加到 R 中的交叉表
- elasticsearch - 按用户折叠计算百分位数
- c# - Ninject ASP.NET MVC 项目中的数据注入
- python - PyMongo - 使用辅助节点作为种子时写入主节点
- c++ - 迭代 C++ 中的元组类型
- google-chrome - 如何删除 url 的所有数据 chrome 存储?
- kubernetes - 牧场主集群 kubernetes 上的插件 grafana “grafana-image-renderer”
- python - 按日期组合系列