【发布时间】:2021-06-04 07:33:13
【问题描述】:
我有一个包含我的数据的 excel 文件。就是这个: enter image description here 在读取并将其存储在“数据”变量中之后,我想将其分成两部分并将它们中的每一个分配给不同的变量。我的意思是我想从我的数据输入中提取 2 个形状不一致的矩阵。 例如,如果我的数据是我放在这里的图片,我想要这两个: enter image description here 和 enter image description here 我使用了这个索引,但它没有用。 这是代码:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
FilePath='E:\\# Civil Engineering graduate\\Projects\\Python\\RoutePlanning'
FileName='\\Data.xlsx'
Data=pd.read_excel(FilePath+FileName)
print(Data)
Points=np.array(Data[1:,0:3])
这是它所经历的错误:
Exception has occurred: TypeError
'(slice(1, None, None), slice(0, 3, None))' is an invalid key
File "E:\# Civil Engineering graduate\Projects\Python\RoutePlanning\RoutePlanning.py", line 9, in <module>
Points=np.array(Data[1:,0:3])
我见过很少有为此目的使用循环和函数定义的解决方案,除非我必须... 肯定我在这里索引时犯了一个错误,因为它不起作用。但我想知道这是否可以修复并投入使用,或者是否有任何类似索引的解决方案。 如果没有,什么是性能最好的解决方案。
【问题讨论】:
-
请提供示例数据框,以便我们更好地帮助您
标签: python pandas numpy indexing data-structures