简体   繁体   English

使用熊猫从不同的Excel工作表中的行中获取特定的字符串

[英]Using Pandas to get a certain string from a row in different excel sheets

I have an excel file with different sheets, each sheet containing cities names with some data. 我有一个Excel文件,其中包含不同的工作表,每个工作表都包含带有一些数据的城市名称。 For example: 例如:

Istanbul  Paris Barcelona
1          2        3
4          2        6

In every sheet, I want to extract the row for each cell where Paris = 2. So far, I have : 在每张工作表中,我想提取巴黎= 2的每个单元格的行。到目前为止,我有:

import pandas
xls= pandas.ExcelFile('cities.xlsx')
sheets= xls.sheet_names
print sheets
#Dialogue Result
for row in sheets.iter_rows():
   row = sheet.row("Paris")
   print row.index()

You can using pd.concat 您可以使用pd.concat

import pandas as pd
xls = pd.ExcelFile('path_to_file.xls')
alldf=pd.concat([xls.parse(x) for x in xls.sheet_names],keys=xls.sheet_names)

alldf.loc[alldf.Paris==2,:]

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

相关问题 使用pandas组合/合并2个不同的Excel文件/工作表 - Using pandas Combining/merging 2 different Excel files/sheets 使用 Pandas 连接 excel 表 - Concatenate excel sheets using Pandas 从 Pandas 格式化 Excel 表 - Formatting Excel sheets from Pandas 如何使用 Pandas 从 Excel 中只读取可见的工作表? - How to read only visible sheets from Excel using Pandas? 使用Python将Excel中的单元格从不同的工作表复制到一个工作表 - copy cell from Excel from different sheets to one using Python 如何使用 openpyxl / pandas 或任何 python 将从几个 excel 工作表中提取的字符串数据保存到新工作簿? - How do I save the string data I have extracted from several excel sheets to a new workbook using openpyxl / pandas or anything python? 从 pandas 系列中的每一行中提取某个字符串的最后一次出现 - Extracting last occurrence of a certain string from each row in a pandas series 使用pandas比较具有不同行值和坐标的两个excel电子表格 - Compare two excel spreadsheets with different row values and coordinates using pandas 如何使用 Python 3 和 Pandas 从多个 Excel 工作表中提取相同的行号并将其放在一起? - How can I use Python 3 and pandas to extract and put together same row numbers from multiple excel sheets? 如何使用 pandas 从目录中的 excel 表中获取每一行值 - How to get each row value from excel sheet in a directory using pandas
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM