OptionError:'Pattern matched multiple keys' pandas
Asked Answered
H

6

13

I am trying to read a excel file.

import requests
url = 'http://www.nepalstock.com/todaysprice/export'
r = requests.get(url, allow_redirects=True)
open('todayprice.xls', 'wb').write(r.content)

import pandas as pd
pd.set_option("xls", "openpyxl")
fileurl='todayprice.xls'
df=pd.read_excel(fileurl)
print(df)

I get an error saying:

raise OptionError("Pattern matched multiple keys")
pandas._config.config.OptionError: 'Pattern matched multiple keys'
Holland answered 29/3, 2021 at 8:42 Comment(0)
L
27

This error often happens when people use older codes for pandas options, like precision. Starting in 1.4 some of these are replaced with longer forms, like display.precision.

Solution: visit list of options in pandas docs and find the updated name for your option.

I'd like to add that the error message Pattern matched multiple keys is quite confusing. Pandas team may want to change it.

Lyre answered 18/4, 2022 at 9:39 Comment(0)
L
15

In the new Pandas version, you need to use the code below to get the desired output.

pd.options.display.max_rows = 5
Lenient answered 12/9, 2022 at 13:4 Comment(1)
Never write something like "the new pandas version", it'll age terribly. Be specific: "pandas 1.4+" or whatever.Discernible
V
3

Both Pd.set_option("display.max_columns",100) And Pd.options.display.max_columns=100

Perform the same role

Vidar answered 21/2, 2023 at 20:10 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Frangipane
R
2

pd.set_option("display.max_columns", 100) solved my problem.

https://pandas.pydata.org/pandas-docs/stable/user_guide/options.html

Ravel answered 30/1, 2023 at 15:27 Comment(0)
S
1

You can try with the option io.excel.xls.reader instead of just xls.

From the doc:

Regexp which should match a single option. Note: partial matches are supported for convenience, but unless you use the full option name (e.g. x.y.z.option_name), your code may break in future versions if new options with similar names are introduced.

Shulman answered 29/3, 2021 at 9:56 Comment(0)
B
0

Tried various methods like: pd.set_option('max_columns', 35)

but the below format will surely help:

pd.set_option("display.max_columns", 100)

https://pandas.pydata.org/pandas-docs/stable/user_guide/options.html

Bearer answered 21/3, 2023 at 10:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.