这里是python新手,我如何让python读取一排单元格,比如在excel上读取100,200,300,然后确保代码然后等于x=100,y=200,z=300?
如果你能把你的 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
非常感谢@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)