1

i do have an excel file:

<>   1    2    3
A
B
C

with my data in each cell.

in another sheet i do have my description:

    name    pH    salt    id
A1    sample    8.5    50    1
A2    sample    8.5    50    1
A3    sample    8.5    50    2
B1    sample    7.5    50    2

reading the data and the labels:

d = pd.read_excel(data_name,'280', index_col = 0)
d_label =pd.read_excel(data_name,'label', index_col = 0)

creating a list from the data:

data = list(chain.from_iterable(d.values.tolist()))

making a multiindex:

index = pd.MultiIndex.from_tuples(tuple(d_label.values), names=d_label.columns)

when I created a series:

s = pd.Series(data, index = index)

I can now index the series as usual. E.g.

s['some_name']

But if i do:

df = pd.DataFrame(data, index = index)

and:

df['some_name']

i get an error:

'no item named some_name'

What did I wrong ?

1
  • You leave me extremely confused. "Series containing index": Either you're doing something weird, or you describe it weirdly - or perhaps its just me. Please state the shape of your data and what you're exactly trying to achieve. Commented May 27, 2014 at 10:57

1 Answer 1

1

See the basic indexing documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#basics

When indexing a Series, s['some_name'] will access the row with label some_name.
While when indexing a DataFrame, df['some_name'] will access the column (and not row index) with label some_name. You can do df.loc['some_name'] to access a row.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.