pandas dataframe string formatting (access a given column)
问题 I try to use new-style formatting to display the entry at a given/specified column: np.random.seed(1234) df = pd.DataFrame(np.random.randint(7, size=(2, 2)), columns=['a', 'b']) c = df.iloc[0, :] # get row number 0 print("Here is {one[0]} and {two}".format(one=c, two=c['b'])) # Ok But I'd like to do it as follows: print("Here is {one['a']} and {two}".format(one=c, two=c['b'])) ## Unfortunately KeyError: "'a'" Is it possible to do that and how? 回答1: I think you can remove '' in one['a'] :