0

Using Jupyter Notebook, if I put in the following code:

import pandas as pd

df = pd.read_csv('path/to/csv')

while True:
    df

The dataframe won't show. Can anyone tell me why this is the case? I'm guessing it's because the constant looping is preventing the dataframe from loading fully. Is that what's happening here?

I need code that would let me get a user's input. If they type in a name, for example, I'll extract the person with that name's info from the dataframe and display it, then the program needs to ask them to give another name. This will continue until they type in "quit". I figured a while loop would be the best for that, but it looks like there's just something about while loops and pandas that won't mix. Does anyone have any suggestions on what I can do instead?

togogh
  • 9
  • 4
  • But why do you want to do this? If you want to see df, just do `df` or `df.head()` – YOLO May 05 '18 at 13:22
  • 3
    Try `display(df)` – Georgy May 05 '18 at 13:26
  • Possible duplicate of [IPython Notebook cell multiple outputs](https://stackoverflow.com/questions/34398054/ipython-notebook-cell-multiple-outputs) – Georgy May 05 '18 at 13:31
  • I guess it's because Jupyter prints out just the last line, and your loop juns forever - so there is no last line. Try print – MBT May 05 '18 at 13:32
  • 1
    I can't speak for Jupyter specifically, but this will hammer your CPU in iPython; you don't have a pause in your loop like `time.sleep(1)` – roganjosh May 05 '18 at 13:39
  • @YOLO The plan is to do the following: 1. Ask user for input. 2. WHILE user hasn't typed in "quit", extract data they need from dataframe and ask them what their input is again. – togogh May 05 '18 at 13:47
  • 1
    @Georgy Thanks!!! That worked :D – togogh May 05 '18 at 13:47
  • @blue-phoenox I didn't think of that possibility, good inference. I'm not sure that's the case though, because print works. It's just that print looks ugly lol, just plain text, nothing like the pandas table. – togogh May 05 '18 at 13:47
  • @roganjosh Ah, I didn't think of that. Thanks for pointing that out! – togogh May 05 '18 at 13:47

0 Answers0