Python如何使用NumPy导入xlsx文件 [英] Python How to Import xlsx file using numpy

查看:0
本文介绍了Python如何使用NumPy导入xlsx文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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:Usersfkrueg1Dropboxforest_python_testGraph_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 更简单

这篇关于Python如何使用NumPy导入xlsx文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆