0

enter image description hereI am trying to get a specific set of rows from 30 different excel tabs that are labeled by a date in column 1 of each excel tab. There are rows with the same date but are different in each tab. For example, I want the three columns of data in the same row of the row labeled '2019-08-08' from every tab and put it in a separate excel file.

import pandas as pd

df = pd.read_excel('mouse.xlsx', sheet_name=None, skiprows=5)

for name, sheet in df.items():

     sheet['sheet'] = name

Sunday = '2019-08-08'

sheet.loc(Sunday)

When I run sheet.loc, python is unable to find any data on 'sheet'

  • No data images on SO plz. [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – Trenton McKinney Sep 01 '19 at 16:34

1 Answers1

1

IIUC, use

df.loc[df['Date'] == '2019-08-08']

Pass sunday as a variable not string

M_S_N
  • 2,764
  • 1
  • 17
  • 38
  • This does not work and I get the error: ValueError: No axis named 2019-08-08 for object type – spencersmith Sep 01 '19 at 16:26
  • Check image i uploaded – spencersmith Sep 01 '19 at 16:28
  • I just added an example photo that I get when I run: 'sheet'. In this case I want to use the date 2019-08-20 – spencersmith Sep 01 '19 at 16:30
  • what i understand is that, from this sheet dataframe, you want to select a ROW where date is 2019-08-20. Right?. if so, sheet[date]=='2019-08-20' – M_S_N Sep 01 '19 at 17:41
  • That is correct. That works to find the specific row, but how do i put the data from that row into another dataframe for every sheet in my excel file? – spencersmith Sep 01 '19 at 22:24
  • "put the data from that row into another dataframe" assign it to a variable, for every sheet go through these posts.1) https://stackoverflow.com/questions/42370977/how-to-save-a-new-sheet-in-an-existing-excel-file-using-pandas 2) https://stackoverflow.com/questions/54186519/appending-pandas-dataframe-to-existing-excel-document 3) https://stackoverflow.com/questions/38074678/append-existing-excel-sheet-with-new-dataframe-using-python-pandas – M_S_N Sep 01 '19 at 22:42