简体   繁体   English

如何使用 python 读取 excel 上的数据,然后将单元格等同于不同的变量,例如。 x、y、z 等

[英]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.

相关问题 如何将 X,Y,Z,Value 数据转换为 python 中的数组? - How can I turn X,Y,Z,Value data into an array in python? 如何使用Python从地理数据中提取x,y和z坐标? - How can I extract x, y and z coordinates from geographical data by Python? Python数据[i]到数据[i + 100] &lt;#(例如50) - Python data[i] to data[i+100] < # (eg. 50) 我应该如何在Python中包装一个交互式子进程(例如shell) - How should I wrap an interactive subprocess (eg. shell) in Python 如何在以下 python 代码中提取变量 X2 和 Y2 的正确数据? - How can I extract the correct data for the variables X2 and Y2 in the following python code? 你如何使用字符串操作在python中创建一个由x框组成的X? (例如,替换,计数,查找,len等) - How do you create a n by n box of X's in python using string manipulation? (eg. replace, count, find, len, etc.) 如何使用Numpy在文本文件的三列中写入三个不同的值(x,y,z)? - How can I write three different values(x, y, z) in three columns a text file using Numpy? 如何将y = pow(x,z)求反得到x? - How can I invert y = pow(x, z) to get x? 如何从 Python 中的插值网格中提取 (x,y,z) 值 - How can I extract (x,y,z) values from an interpolated grid in Python 如何在 Python 的数据集列表中提取 X、Y、Z 的值? - How can I extract out the value of X, Y, Z in a list of dataset in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM