Есть гугл таблица, в ней 2 листа.
Читаю первый лист:
tables = pd.read_html('https://docs.google.com/********', encoding='utf-8')
df = pd.DataFrame(tables[0])
first_rowA = df[['A', 'B', 'C']].dropna()
print(first_rowA.to_string(index=False, header=False))
- успех.
Пытаюсь прочитать второй лист, меняя индекс на 1
(df = pd.DataFrame(tables[1])) - непонятная ошибка. Ок, пошел другим путем, чтобы проверить работу в принципе:
tables = pd.read_html('https://docs.google.com/****************', encoding='utf-8')
first_rowA = tables[1]
print(first_rowA.head())
В данном случае выводит имя первого и второго листа таблицы, но если я тут же поменяю на
first_rowA = tables[0], то корректно будет выводить всю таблицу первого листа. В чем подвох?
Traceback:
Traceback (most recent call last):
File "c:\progect\bot.py", line 23, in <module>
first_rowA = df[['A', 'B', 'C']].dropna()
File "C:\Users\***\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\frame.py", line 4119, in __getitem__
indexer = self.columns._get_indexer_strict(key, "columns")[1]
File "C:\Users\***\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\indexes\base.py", line 6212, in _get_indexer_strict
self._raise_if_missing(keyarr, indexer, axis_name)
File "C:\Users\***\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\indexes\base.py", line 6261, in _raise_if_missing
raise KeyError(f"None of [{key}] are in the [{axis_name}]")
KeyError: "None of [Index(['A', 'B', 'C'], dtype='object')] are in the [columns]"