1

I have a big data frame that contains 6 columns. When I want to print the info out of one cell, I use the following code:

df = pd.read_excel(Path_files_data)
info_rol = df.loc[df.Rank == Ranknumber]
print(info_rol['Art_Nr'])

Here Rank is the column that gives the rank of every item and Ranknumber is the Rank of the item i try to look up. How what i get back looks like this:

0    10399
Name: Art_Nr, dtype: object

Here 0 is the rank and 10399 is Art_Nr. How do I get it to work that it only printsout the Art_Nr. and leaves al the crap like dtype: object.

PS. I tried strip but that didnt work for me.

marc_s
  • 675,133
  • 158
  • 1,253
  • 1,388
Erik Franke
  • 55
  • 1
  • 2
  • 6
  • Sure, this is very easy. Just subclass `pd.Series` and modify its `__repr__` method. – cs95 Nov 11 '17 at 17:36
  • Actually, I'm intrigued by what you mean by "crap". What exactly do you want left out? Only the `dtype`? Or do you just want to print the numerical value? – cs95 Nov 11 '17 at 17:38
  • Possible duplicate of [Suppress descriptive output when printing pandas dataframe](https://stackoverflow.com/questions/24295451/suppress-descriptive-output-when-printing-pandas-dataframe) – DJK Nov 11 '17 at 18:44
  • @djk47463 That's a very interesting duplicate. What about the col name though? – cs95 Nov 11 '17 at 19:02
  • @cᴏʟᴅsᴘᴇᴇᴅ, OP is just calling a series from the dataframe `info_rol['Art_Nr']`, which doesn't print a column header. That is printed as the `Name:` of the series at the bottom, which isnt shown when using the code from the dupe – DJK Nov 11 '17 at 19:20
  • @djk47463 yeah, so OP wants the column name I think... not sure the dupe is 100% applicable here. Well, worst case, they can just append it to `to_string` :D – cs95 Nov 11 '17 at 19:24
  • @cᴏʟᴅsᴘᴇᴇᴅ, I not sure he does want the column header, he wants the "crap" at the bottom of a series print removed. But if so wouldnt OP just be asking how to print as a dataframe instead of a series? `print(info_rol[['Art_Nr']])` – DJK Nov 11 '17 at 19:27
  • @djk47463 Possibly... I'd put that into an answer, add an example with some sample data. – cs95 Nov 11 '17 at 19:28

1 Answers1

0

I think you need select first value of Series by iat or iloc for scalar:

print(info_rol['Art_Nr'].iat[0])

print(info_rol['Art_Nr'].iloc[0])

If string or numeric output:

print(info_rol['Art_Nr'].values[0])

But after filtering is possible you get multiple values, then second, third.. values are lost.

So converting to list is more general solution:

print(info_rol['Art_Nr'].tolist())
jezrael
  • 629,482
  • 62
  • 918
  • 895