questions on how to output non-string objects into one or more lines of text, for instance numbers (precision, justify), or arrays (placing separators, newlines)
Questions tagged [output-formatting]
119 questions
863
votes
22 answers
How do I print the full NumPy array, without truncation?
When I print a numpy array, I get a truncated representation, but I want the full array.
>>> numpy.arange(10000)
array([ 0, 1, 2, ..., 9997, 9998, 9999])
>>> numpy.arange(10000).reshape(250,40)
array([[ 0, 1, 2, ..., 37, 38, …

kame
- 20,848
- 33
- 104
- 159
462
votes
8 answers
Alternate output format for psql showing one column per line with column name
I am using PostgreSQL 8.4 on Ubuntu. I have a table with columns c1 through cN. The columns are wide enough that selecting all columns causes a row of query results to wrap multiple times. Consequently, the output is hard to read.
When the query…

user100464
- 17,331
- 7
- 32
- 40
316
votes
17 answers
How to show full column content in a Spark Dataframe?
I am using spark-csv to load data into a DataFrame. I want to do a simple query and display the content:
val df = sqlContext.read.format("com.databricks.spark.csv").option("header", "true").load("my.csv")
df.registerTempTable("tasks")
results =…

tracer
- 3,265
- 2
- 15
- 6
284
votes
8 answers
Why do I get "TypeError: not all arguments converted during string formatting" trying to substitute a placeholder like {0} using %?
I have some code which will read two strings from the user:
name1 = input("Enter name 1: ")
name2 = input("Enter name 2: ")
Later, I want to format those strings into a longer string for printing:
if len(name1) > len(name2):
print ("'{0}' is…

user2652300
- 2,955
- 2
- 13
- 3
147
votes
4 answers
Controlling number of decimal digits in print output in R
There is an option in R to get control over digit display. For example:
options(digits=10)
is supposed to give the calculation results in 10 digits till the end of R session. In the help file of R, the definition for digits parameter is as…

Mehper C. Palavuzlar
- 10,089
- 23
- 56
- 69
101
votes
10 answers
Removing display of row names from data frame
I am creating a dataframe using this code:
df <- data.frame(dbGetQuery(con, paste('select * from test')))
Which results in this:
UID BuildingCode AccessTime
1 123456 BUILD-1 2014-06-16 07:00:00
2 364952 BUILD-2 …

Dom Abbott
- 1,157
- 2
- 8
- 11
74
votes
1 answer
avoid string printed to console getting truncated (in RStudio)
I want to print a long string to the RStudio console so that it does not get truncated.
> paste(1:300, letters, collapse=" ")
[1] "1 a 2 b 3 c 4 d 5 e 6 f 7 g 8 h 9 i
...
181 y 182 z 183 a 184 b...
I supposed this should be fairly…

Mark Heckmann
- 10,943
- 4
- 56
- 88
66
votes
5 answers
Is there a way to output text to the R console in color
I am writing a script and I want to output text messages to the console with different colors depending on conditions. For example: RED for errors and BLUE for warnings, etc.
I am using RStudio.

notuo
- 1,091
- 2
- 9
- 15
63
votes
6 answers
How to format the output of kubectl describe to JSON
kubectl get command has this flag -o to format the output.
Is there a similar way to format the output of the kubectl describe command?
For example:
kubectl describe -o="jsonpath={...}" pods my-rc
would print a JSON format for the list of pods in…

Gabriel Petrovay
- 20,476
- 22
- 97
- 168
58
votes
2 answers
How to control number of decimal digits in write.table() output?
When working with data (e.g., in data.frame) the user can control displaying digits by using
options(digits=3)
and listing the data.frame like this.
ttf.all
When the user needs to paste the data in Excell like this
write.table(ttf.all,…

userJT
- 11,486
- 20
- 77
- 88
53
votes
3 answers
Remove name, dtype from pandas output of dataframe or series
I have output file like this from a pandas function.
Series([], name: column, dtype: object)
311 race
317 gender
Name: column, dtype: object
I'm trying to get an output with just the second column, i.e.,
race
gender
by deleting top and…

pam
- 1,175
- 5
- 15
- 28
53
votes
5 answers
Possible to print more than 100 rows of a data.table?
The data.table has a nice feature that suppresses output to the head and tail of the table.
Is it possible to view / print more than 100 rows at once?
library(data.table)
## Convert the ubiquitous "iris" data to a data.table
dtIris =…

geneorama
- 3,620
- 4
- 30
- 41
52
votes
5 answers
How to output text in the R console without creating new lines?
I would like to output a progress indicator during my lengthy running algorithms. I can easily "bubble up" a progress value from within my algorithm (e.g. via invoking a provided function callback specifically for this purpose), but the difficulty…

DuckMaestro
- 15,232
- 11
- 67
- 85
47
votes
4 answers
How to dump an output from SQL Server Profiler 2008 to a CSV-like file
I am debugging stored procedures, and right now I am interested in what ran in what order and which which parameters as opposed to how fast things ran and what may sneak in between and cause a slowdown.
So, I captured a couple of minutes worth of…

Hamish Grubijan
- 10,562
- 23
- 99
- 147
39
votes
5 answers
Overriding "Variables not shown" in dplyr, to display all columns from df
When I have a column in a local data frame, sometimes I get the message Variables not shown such as this (ridiculous) example just needed enough columns.
library(dplyr)
library(ggplot2) # for movies
movies %.%
group_by(year) %.%
…

Hugh
- 15,521
- 12
- 57
- 100