简体   繁体   English

如何使用数据提供程序读取 python 中的 excel 文件

[英]How to read excel file in python using data provider

Is there any way in python to read excel file like we have data provider in the testng i am having a test method (using python unit test framework) and from this test i am calling another method which is actually reading the excel sheet, I just want something like data provider so that with every data it should be treated as a new test case Is there any way in python to read excel file like we have data provider in the testng i am having a test method (using python unit test framework) and from this test i am calling another method which is actually reading the excel sheet, I just想要像数据提供者这样的东西,这样每个数据都应该被视为一个新的测试用例

You could use pandas to read the excel files or csv files.您可以使用 pandas 来读取 excel 文件或 csv 文件。

import pandas as pd

excel_data = pd.read_excel('test_file.xlsx')
csv_data = pd.read_csv('test_file.csv')

And the result is DataFrame structure.结果是 DataFrame 结构。

Use Pandas to read excel files in Python.使用 Pandas 读取 Python 中的 excel 文件。 From your question I assume you don't know about pandas.根据您的问题,我假设您不了解 pandas。

If you have added python to path during installation of IDE.如果您在安装 IDE 期间将 python 添加到路径。 Use pip for installation in the terminal使用pip安装在终端

py -m pip install pandas 

The python code is python 代码是

import pandas as pd
df=pd.read_excel('Data.xlsx')
print(df.head()) # This will print the first 5 rows.

if you want to use jupyter notebook in the terminal如果你想在终端中使用 jupyter notebook

py -m pip install notebook

This will work best.这将最有效。 But you need to have pandas installed through pip.但是您需要通过 pip 安装 pandas。 For adavanced functions or atleast update question to what you want.对于高级功能或至少更新您想要的问题。 What is it that dataprovider does, so as to repeat it in python Specify the fuction dataprovider是做什么的,所以在 python 中重复指定功能

Go through pandas documentation: https://pandas.pydata.org/docs/ Go 到 pandas 文档: https://pandas.pydata.org/docs/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 python 中读取 json 数据 excel 文件 - how to read json data excel file in python 使用 PYTHON 读取 JSON 文件并使用该数据创建一个 excel 文件 - Read JSON file using PYTHON and create an excel file with that data 如何从文本文件中读取数据,然后使用 Python 将它们写入 Excel 文件中? - How to read data from a text file then writing them in an Excel file using Python? 如何使用Python从Excel中读取和提取数据并将其粘贴到文本文件中的现有文本中? - How to read and extract data from Excel and paste it into an existing text in a text file using Python? 如何使用 OOP 在 Python3 中创建 Class 以从 Excel 文件加载和读取数据? - How can I create a Class in Python3 using OOP to load and read data from an Excel file? 如何使用 python 在 excel 文件中写入数据 - How to write data in an excel file using python 如何使用python Ubuntu从远程服务器读取Excel文件 - How to read excel file from remote server using python ubuntu 如何使用xlrd在python中按列名读取Excel数据 - How to read Excel data by column name in python using xlrd 如何使用 pandas python 从 excel 读取 MultiIndex 组数据 - How to read MultiIndex group data from excel using pandas python 如何使用python读取Excel文件中的特定行 - How to read a specific row in excel file using python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM