1

I am learning data analysis with the help of a book named'python for data analysis'.Every thing goes well.But i get a problem that i do not know what is going on.

The instruction from the book is:

In [846]: !cat ch06/ex1.csv

But when I input it in canopy, it comes out with

!cat ch06/ex1.csv

Der Befehl "cat" ist entweder falsch geschrieben oder konnte nicht gefunden werden."

The error comment is in german,and it means "the instruction 'cat' is wrong written or can not be found".

What does the '!'mean in this line.?

And the 'cat'? why can't the editor figure it out ?

Do I need to import a module to fix this?

Simon Gibbons
  • 6,969
  • 1
  • 21
  • 34
Tang
  • 303
  • 3
  • 12
  • if you are using windows, this probably will not work. – cel Jul 31 '15 at 15:42
  • 1
    I actually had the same problem. I just manually wrote the csv file, which isn't too difficult because it's very small. – dsaxton Jul 31 '15 at 15:42
  • Yes,i am using windows. but other things work well – Tang Jul 31 '15 at 15:45
  • 1
    `cat` is linux shell commnand, but apparently `type` is equivalent (or was): http://stackoverflow.com/questions/60244/is-there-replacement-for-cat-on-windows – cnluzon Jul 31 '15 at 15:55

4 Answers4

1

If anyone still have this problem from the book, just past the following in a txt file and save it as csv

a,b,c,d,message

1,2,3,4,hello

5,6,7,8,world

9,10,11,12,foo

Then just read the csv file as shown in the book df = pd.read_csv('ex1.csv') without the 'examples/' because that's path for the author.

0

cat is a linux command which concatenate files and print on the standard output. You can use linux commands using "!" operator in ipython but not in python. Hence you are simply trying to use ipython command in python.

Amritbir Singh Gill
  • 366
  • 1
  • 3
  • 12
  • 1
    no. the thing is: `cat` only available from the linux shell. This has nothing to do with `ipython` and `python` per se... – cel Jul 31 '15 at 16:05
0

You can execute linux commands in jupyter notebook(python) by putting "!" in front of a command.

for example

!cat test.txt 

!echo "hello"
Noam Hacker
  • 4,671
  • 7
  • 34
  • 55
0

In my case I added a python function just before the first !cat statement

def ucat(foo):
    file = open (foo, "r")
    contents = file.read();
    print (contents)

Then, I replaced each occurrence of !cat filename with ucat('filename')

Works in Windows, and should work in Linux

n4m31ess_c0d3r
  • 3,028
  • 5
  • 26
  • 35