Q&A
前提
python勉強中です。
表にしたデータから特定の範囲の行を取得する方法がわからず手が止まっています。
実現したいこと
範囲指定し、その範囲の行をすべて取得したいです。
A列の0.15から0.2未満のものを取得したい。
そしてA列の数字は外したいです
期待結果
発生している問題・エラーメッセージ
書き方がわからずA列の指定した数字の行しか取れないです。
該当のソースコード
python
1import openpyxl as op 2import pandas as pd 3 4def serch_column(column,keyword): 5 result = [] 6 for cell in column: 7 try: 8 value == str(cell.value) 9 except: 10 continue 11 12 if value == keyword: 13 cell_address = str(cell.row) 14 result.append(cell_address) 15 return result 16 17def main(): 18 file_path = "data.xlsx" 19 wb = op.load_workbook(file_path) 20 ws = wb["データ"] 21 df = pd.read_excel(file_path) 22 result = serch_column(ws["A"], "0.158") 23 24 print(df.iloc[result]) 25 26if __name__ == "__main__": 27 main()
回答2件
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。