2

I am trying to extract the contents from pandas dataframe without the index.

Dataframe:

 L_No          Exp_date
 LC_139        12/01/2019

When I do L_No = df["L_No"], I get the output with the index rather than just the L_No.

Current output:

 83919     LC_139

Expected output:

 LC_139

1 Answer 1

3

I believe need convert column (Series) to numpy array or list and select first value:

df = pd.DataFrame({'L_No':['LC_139'],'Exp_date':['12/01/2019']})
print (df)
     L_No    Exp_date
0  LC_139  12/01/2019

print(df["L_No"].values[0])
LC_139

print(df["L_No"].values.tolist()[0])
LC_139

If want select by loc for select by labels or iloc for select by positions of first value of column L_No:

#need first label of index
print(df.loc[df.index[0], "L_No"])
LC_139

#need position of column L_No by get_loc
print(df.iloc[0, df.columns.get_loc("L_No")])
LC_139
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.