-2

I've been off the "panda" for a few months but I've had a relapse...

This is my short little script:

import pandas as pd

user_input = pd.read_csv(raw_input("Enter file-path: "),sep=r'\s+')
get_Info =user_input[user_input['Monid'].str.contains(raw_input("Enter a star: "))]

for value in get_Info.values:
    print value

My intent is to print the values of get_Info.values into a string rather than the array that pandas prints them out as, like so:

[Mon-000005 99.999 19.67 18.242 17.134 15.722 99.999 99.999 99.999 99.999
 14.254 0.044 13.532 0.043 13.33 0.042 13.154 0.007 13.106 0.008 12.968
 0.04 12.985 0.115 99.999 99.999 M3 6.56 1 N]

I can remove those brackets with a str.replace after converting the output via a str() defining, but that doesn't seem too efficient. Even after doing that it still has the line breaks as seen above. I'd like to just print it out as one string, not three separate lines. I'm not sure how to do that, and why is it breaking the lines in the first place?

Thanks.

Matt
  • 3,508
  • 6
  • 38
  • 66
  • possible duplicate of [python print array without brackets in a single row](http://stackoverflow.com/questions/11178061/python-print-array-without-brackets-in-a-single-row) – sashkello Nov 22 '13 at 03:52
  • Yeah except the line still breaks. Hence, new question. – Matt Nov 22 '13 at 03:58
  • What do you mean by line breaks? Have you tried to just make your terminal full screen? If I understand it correctly. – sashkello Nov 22 '13 at 04:00
  • Yes I've tried that. What I placed above occurs no matter what despite the screen size. – Matt Nov 22 '13 at 04:02

1 Answers1

1

See if that helps.

print (''.join(get_Info.values)).replace('\n','')
duck
  • 2,483
  • 1
  • 24
  • 34
  • Your suggestion works for taking care of the unwanted line break. But if I keep the `(' '.join(blah blah))` in there it puts a white space between every character. But the .replace('\n','') works wonderfully. Thanks. If you edit your answer I'll accept it. – Matt Nov 22 '13 at 04:05
  • Also, why is it putting new-lines in such a seemingly random spot? – Matt Nov 22 '13 at 04:06
  • I am not sure regarding that, may be the contents of csv were like that – duck Nov 22 '13 at 04:12
  • It's not printed like that in my file...weird. Thanks again. – Matt Nov 22 '13 at 04:12