Why do I get “TypeError: not all arguments converted during string formatting” trying to substitute a placeholder like {0} using %?

Old-style % formatting uses % codes for formatting: # A single value can be written as is: ‘It will cost $%d dollars.’ % 95 # Multiple values must be provided as a tuple: “‘%s’ is longer than ‘%s'” % (name1, name2) New-style {} formatting uses {} codes and the .format method. Make sure not to … Read more

Alternate output format for psql showing one column per line with column name

I just needed to spend more time staring at the documentation. This command: \x on will do exactly what I wanted. Here is some sample output: select * from dda where u_id=24 and dda_is_deleted=’f’; -[ RECORD 1 ]——+—————————————————————————————————————————————————————————————————————- dda_id | 1121 u_id | 24 ab_id | 10304 dda_type | CHECKING dda_status | PENDING_VERIFICATION dda_is_deleted | … Read more

Output file doesn’t match Write-Host

Caveat: Write-Host is meant for to-display output, not for outputting data – it bypasses PowerShell’s success output stream (PowerShell’s stdout equivalent), so that output from Write-Host cannot (directly[1]) be captured in a variable, nor redirected to file – see the bottom half of this answer for more information. Use Write-Output or – preferably – PowerShell’s … Read more

Formatting output in C++

Off the top of my head, you can use setw(int) to specify the width of the output. like this: std::cout << std::setw(5) << 0.2 << std::setw(10) << 123456 << std::endl; std::cout << std::setw(5) << 0.12 << std::setw(10) << 123456789 << std::endl; gives this: 0.2 123456 0.12 123456789

Remove name, dtype from pandas output of dataframe or series

DataFrame/Series.to_string These methods have a variety of arguments that allow you configure what, and how, information is displayed when you print. By default Series.to_string has name=False and dtype=False, so we additionally specify index=False: s = pd.Series([‘race’, ‘gender’], index=[311, 317]) print(s.to_string(index=False)) # race # gender If the Index is important the default is index=True: print(s.to_string()) #311 … Read more

Removing display of row names from data frame

You have successfully removed the row names. The print.data.frame method just shows the row numbers if no row names are present. df1 <- data.frame(values = rnorm(3), group = letters[1:3], row.names = paste0(“RowName”, 1:3)) print(df1) # values group #RowName1 -1.469809 a #RowName2 -1.164943 b #RowName3 0.899430 c rownames(df1) <- NULL print(df1) # values group #1 -1.469809 … Read more