【问题标题】:Dealing with .csv files: Error: only integer scalar arrays can be converted to a scalar index处理 .csv 文件:错误:只能将整数标量数组转换为标量索引
【发布时间】:2020-09-16 18:35:02
【问题描述】:

enter image description herePython 机器学习处理 .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

【问题讨论】:

  • 大家好,我从 dukascopy.com 下载了 CSV 文件框架中的货币趋势,但无法处理。如果你能帮我找出我的错误,我将非常感激
  • CSV 文件的外观、标题和原始数据有助于理解数据格式。请将其作为示例输入数据添加到您的问题中
  • 感谢您的第一个建议。我从 CSV 文件的表格中上传了一张图片。清楚吗?很明显吗?

标签: python pandas csv dataframe indexing


【解决方案1】:

问题是您将嵌套列表传递给列名,因此创建了'broken' 一级MultiIndex,需要删除外部[]

df.columns = ['date', 'open', 'high', 'low', 'close', 'volume']

【讨论】:

    猜你喜欢
    • 2020-09-24
    • 2018-09-27
    • 2020-04-30
    • 2020-07-23
    • 2018-05-29
    • 2019-03-15
    • 2021-02-09
    • 1970-01-01
    • 2020-04-20
    相关资源
    最近更新 更多