0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

エクセルファイルから基準となる文字のセルを見つけてデータを読み込む

Last updated at Posted at 2021-06-08

we shall find 'uko' and 'kare-' in a excel file.
because it's my life.

python
import pandas as pd
import numpy as np

DATA_OFFSET_COL = 1
DATA_OFFSET_ROW = 2
INTERVAL = 11
UNCOL = 9
MAX_EVENT_NUM = 9
MAX__NUM_SEQUENCE = 5

df = pd.read_excel('pd_debug.xlsx')
okng = df.iloc[:,UNCOL]
event = df.iloc[:,UNCOL+DATA_OFFSET_COL]
data = df.iloc[:,UNCOL+DATA_OFFSET_COL+1]

ok_row_list = okng[(okng=='uko') | (okng=='kare-')].index

for i, j in enumerate(ok_row_list):
    event_list = []
    for eve in range(MAX_EVENT_NUM):
        event_index = DATA_OFFSET_ROW+j+eve
        if event_index >= len(event):
            break            
        event_list.append(event[event_index])

    if i==0:
        s = pd.Series(event_list)
    else:
        s = pd.concat([s, pd.Series(event_list)], axis=1) 
s.columns=np.arange(MAX__NUM_SEQUENCE)

print(s)
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?