Mark K
Mark K

Reputation: 9348

Dataframe extracted from email, ValueError: Cannot index with multidimensional key

A dataframe extracted from email (email saved to local disk, ".msg"), that I am not able to read its content.

The dataframe extracted from email, when wrote to an Excel file, it looks like the screenshot.

It as extra lines on the front rows (#1, #2, #3) with grids. I've only worked with dataframe that normally has 1 top row (not sure if it's called Header).

What's wanted is to read the correspondent cells. For example, to get the First Name in the dataframe, I've tried:

first_name = df.loc[df['Field'] == 'First Name', 'Value'].iloc[0]
print (visitor_name)

It gives error:

ValueError: Cannot index with multidimensional key

How can I do with this type of dataframe? (Here is the saved Excel file, https://filetransfer.io/data-package/6nOhcLTc#link)

enter image description here

Upvotes: 0

Views: 138

Answers (1)

inquirer
inquirer

Reputation: 4823

Did the following:

df = pd.read_excel('Sample.xlsx', engine='openpyxl')
print(df[df['Field'] == 'First Name']['Value'])

Output

6    David

If an error occurs, use the link

pip3 install openpyxl

Upvotes: 1

Related Questions