ValueError长度不匹配

时间:2019-10-30 01:17:54

标签: python pandas csv

尝试打印一些值,但我不断收到错误消息。

我试图在Google和Google上搜索类似的问题。

import pandas as pd
import numpy as np
from scipy.signal import argrelextrema
import matplotlib.pyplot as plt
import datetime


#Import our historical data
data = pd.read_csv('Data/sample.csv', sep='\t')
data.columns = [['Date', 'open', 'high', 'low', 'close', 'vol']]
data = data.drop_duplicates(keep=False)
data.Date = pd.to_datetime(data.iloc(0)[0].Date, format='%Y.%m.%d %H:%M:%S.%f')
data = data.set_index(data.Date)
data = data[['open', 'high', 'close', 'vol']]

price = data.close.iloc[:100]

# Find our relative extrema
max_idx = argrelextrema(price.values,np.greater,order=1)
min_idx = argrelextrema(price.values,np.less,order=1)

print(max_idx)
print(min_idx)

错误消息:

UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
  data.Date = pd.to_datetime(data.iloc(0)[0].Date, format='%Y.%m.%d %H:%M:%S.%f')
Traceback (most recent call last):
  File "untitled.py", line 13, in <module>
    data = data.set_index(data.Date)
  File "/home/uname/.local/lib/python3.6/site-packages/pandas/core/frame.py", line 4442, in set_index
    len_self=len(self), len_col=len(arrays[-1])
ValueError: Length mismatch: Expected 2517 rows, received array of length 1

0 个答案:

没有答案