format

Why does VS-Code Autopep8 format 2 white lines?

Why does VS-Code Autopep8 format 2 white lines? Question: print(“Hello”) def world(): print(“Hello”) world() Gets corrected to: print(“Hello”) def world(): print(“Hello”) world() I have tried to: Reinstall Virtual Studio Code Reinstall Python 3.8 Computer Reboot Using other formatters like Black and yapf but got the same result Asked By: Jakkalsie || Source Answers: Because autopep8 …

Total answers: 3

Python read binary file of unsigned 16 bit integers

Python read binary file of unsigned 16 bit integers Question: I must read a binary file in Python, and store its content in an array. The information I have on this file is that filename.bin is of size 560×576 (height x width) with 16 b/p, i.e., unsigned 16-bit integer for each pixel This is what …

Total answers: 1

Converting from float to percentage

Converting from float to percentage Question: I would like to convert a decimal number (say 0.33333) to percentage (expected answer 33.33%) I used the following x = 0.3333 print(format(x,’.2%’)) which gives indeed 33.33% However, the result is a string, I would like it to still be a number (in % format) to be able to …

Total answers: 4

hook into the builtin python f-string format machinery

hook into the builtin python f-string format machinery Question: Summary I really LOVE f-strings. They’re bloody awesome syntax. For a while now I’ve had an idea for a little library– described below*- to harness them further. A quick example of what I would like it do: >>> import simpleformatter as sf >>> def format_camel_case(string): … …

Total answers: 1

Transform pandas DataFrame from wide to long and count occurrences of a unique value

Transform pandas DataFrame from wide to long and count occurrences of a unique value Question: I have a pretty specific problem that I sadly can not work my mind around. The DataFrame I want to transform currently looks like this: df_larceny CATEGORY INCIDENTYEAR INCIDENTMONTH LARCENY 2009 1 LARCENY 2009 1 LARCENY 2009 1 ……………………….. ……………………….. …

Total answers: 1

How to format a float with space between thousands, millions, etc

How to format a float with space between thousands, millions, etc Question: With : pd.options.display.float_format = ‘{:,}’.format It displays for number x = 1234567.888 : 1,234,567.888 What is the appropriate format to show 0 decimals and add a space between thousands, millions, billions, and so on ? Like this 1 234 568 Asked By: Vincent …

Total answers: 1

How can I filter by image format on the dialog window when I upload an image in Odoo?

How can I filter by image format on the dialog window when I upload an image in Odoo? Question: I have a model with an image attribute: image = fields.Binary( string=”Imagen”, required=True ) Inside the view a show it with: <field name=”image” widget=”image” /> This open an operating system dialog window that allows me to …

Total answers: 2

Is there a string formatting operator in R similar to Python's %?

Is there a string formatting operator in R similar to Python's %? Question: I have a url that I need to send a request to using date variables. The https address takes the date variables. I’d like to assign the dates to the address string using something like the formatting operator % in Python. Does …

Total answers: 3

Format decimals as percentages in a column

Format decimals as percentages in a column Question: Let’s say I have the following pandas DataFrame: df = pd.DataFrame({‘name’: [‘Johnny’, ‘Brad’], ‘rating’: [1.0, 0.9]}) I want to convert the rating column from a decimal to a percentage as a string (e.g. 1.0 to ‘100%’). The following works okay: def decimal_to_percent_string(row): return ‘{}%’.format(row[‘rating’] * 100) df[‘rating’] …

Total answers: 4