2

I am trying to extract 150 lines in random from a dataset of 500 lines. So I would do it at random.

My data

 object,color,label puppy,white,animal mango,orange,fruit pants,black,clothing 

My script

 import pandas import pandas as pd df = pd.read_csv ('data.csv', sep = ',') data_random = df.sample (150) print (data_random) 

But the result is very strange, I do not have the complete line...

 object ... label 277 grape ... fruit 116 bear ... animal 495 ... ... ... 

Is it possible to have the full line?

2
  • 1
    How working pd.options.display.max_columns = 20 ? Commented Aug 24, 2018 at 7:57
  • 1
    pandas.DataFrame.sample only samples according to rows (unless specified otherwise, but you didn't), so it must be a display problem. Try and check data_random.shape it should have the same number of columns as df. Commented Aug 24, 2018 at 7:59

2 Answers 2

2

You can check docs for pandas 0.23.0:

Previously, the default value for the maximum number of columns was pd.options.display.max_columns=20. This meant that relatively wide data frames would not fit within the terminal width, and pandas would introduce line breaks to display these 20 columns.

If Python runs in a terminal, the maximum number of columns is now determined automatically so that the printed data frame fits within the current terminal width (pd.options.display.max_columns=0) (GH17023). If Python runs as a Jupyter kernel (such as the Jupyter QtConsole or a Jupyter notebook, as well as in many IDEs), this value cannot be inferred automatically and is thus set to 20 as in previous versions. In a terminal, this results in a much nicer output.


Note that if you don’t like the new default, you can always set this option yourself. To revert to the old setting, you can run this line:

pd.options.display.max_columns = 20 
Sign up to request clarification or add additional context in comments.

Comments

1

As mentioned, check the Pandas options:

pd.options.display.max_columns = 20

Otherwise, check the setting of your Editor, try it at Jupyter Notebook

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.