我沒有問題使用numpy導入csv數據,但不斷收到我的xlsx文件的錯誤。如何將xlsx文件轉換爲csv或如何將xlsx文件導入x2變量?Python如何使用numpy導入xlsx文件
from matplotlib import pyplot as pp
import numpy as np
#this creates a line graph comparing flight arrival time, arrival in queue, and processing time
x,y = np.loadtxt ('LAX_flights.csv',
unpack = True,
usecols = (1,2),
delimiter = ',')
print("Imported data set arrival time")
x2 = np.loadtext ('First_Persons_PT.xlsx',
unpack = True,
usecols=(0))
print ("Imported start of processing time")
#y2=
#print ("Imported final time when processed")
pp.plot(x,y, 'g', linewidth = 1)
#pp.plot(x2,y, 'y', linewidth = 1)
pp.grid(b=True, which = 'major', color='0', linestyle='-')
pp.title('Comparing Time of Arrival vs. Queue Arrival Time, Queue Finish Time')
pp.ylabel('Arrival in queue (Green),Process Time (Yellow)')
pp.xlabel('Time of arrival')
pp.savefig('line_graph_comparison.png')
以下是錯誤
Imported data set arrival time
Traceback (most recent call last):
File "C:\Users\fkrueg1\Dropbox\forest_python_test\Graph_time_of_arrival.py", line 13, in <module>
x2 = np.loadtext ('First_Persons_PT.xlsx',
AttributeError: 'module' object has no attribute 'loadtext'
的XLSX大約是100號
[openpyxl](https://openpyxl.readthedocs.org/en/latest/)也可以使用,你可以使用[PyPI](https://pypi.python.org/pypi/openpyxl) 'pip install openpyxl' – 2015-04-03 20:01:31