python - 处理 .csv 文件:错误:只能将整数标量数组转换为标量索引
问题描述
在此处输入图像描述Python 机器学习处理 .csv 文件:错误:只能将整数标量数组转换为标量索引
import pandas as pd
df = pd.read_csv('EURGBP.csv')
df.columns = [['date', 'open', 'high', 'low', 'close', 'volume']]
df.date = pd.to_datetime(df.date,format='%d.%m.%Y %H:%M:%S.%f')
df = df.set_index(df.date)
print(df.head())
Error: only integer scalar arrays can be converted to a scalar index
解决方案
问题是您将嵌套列表传递给列名,因此创建'broken'
了一层MultiIndex
,需要删除外部[]
:
df.columns = ['date', 'open', 'high', 'low', 'close', 'volume']
推荐阅读
- c# - 两个不同的类继承自一个抽象类。如何将它们插入字典?
- python - Python Openpyxl:从一个 Excel 工作簿复制并粘贴到另一个 - 内容
- matplotlib - 错误 Matplotlib 添加使用与先前轴相同的参数的轴当前重用早期实例
- python - 扩展 zscore np.vectorize 而不是应用
- java - Thymeleaf 表单请求方法 'POST' 不支持,HTTP 错误 = 方法不允许,状态 = 405
- javascript - 验证错误不会作为 Inertia-vue 中的道具传递
- spring-boot - Spring-boot-jdbcTemplate 单元测试
- node.js - 是否可以在 Google Cloud 运行中重新启动进程
- kubernetes - 在 nginx-ingress 上启用 SSL 的 TCP 服务导致 SSL 握手失败
- excel - 这种不稳定的 VBA 计时器行为是真实的还是我做错了什么