我在使用 numpy 导入 csv 数据时没有遇到任何问题,但我的 xlsx 文件一直出现错误。如何将 xlsx 文件转换为 csv 或如何将 xlsx 文件导入 x2 变量?
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 个数字的列
请您参考如下方法:
import pandas as pd
WS = pd.read_excel('ur.xlsx')
WS_np = np.array(WS)
使用pandas更简单
