[英]How can I use python to read data on excel and then equate the cells to different variables eg. x, y, z etc
New to python here, How would I get python to read a row of cells, say 100, 200, 300 on excel and then make sure the code then equates x=100, y=200, z=300?在这里是 python 的新手,我如何让 python 读取一行单元格,比如 ZBF57C906FA7D2BB66D07372E41585D960Z 上的 100、200、300,然后确保 z=20 等于 z=200?
If you can convert your excel
to csv
then you can do it without pandas
.如果您可以将
excel
转换为csv
,那么您可以在没有pandas
的情况下进行操作。
import csv
rows = list(csv.reader(file(r'your_file.csv', 'r')))
row_0 = rows[0] ## first row
a,b,c = row_0[99],row_0[199],row_0[299] ### 100th, 200th and 300th element
Many Thanks to @Hozayfa El Rifai and @user_3pij for helping with this:非常感谢 @Hozayfa El Rifai 和 @user_3pij 提供帮助:
import csv
def read_csv(file_name='C:\\Users\\aksha\\Downloads\\Blendercsvtest2.csv'):
with open(file_name) as csv_file:
file = csv.reader(csv_file)
return [i for i in file]
csvFileArray = read_csv()
row = csvFileArray[2] # first row
x, y, z, l, m, n, p, q, r = row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9]
x = float(x)
y = float(y)
z = float(z)
l = float(l)
m = float(m)
n = float(n)
p = float(p)
q = float(q)
r = float(r)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.