Reputation: 4158
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
Upvotes: 2
Views: 3308
Reputation: 862921
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
Upvotes: 3