number-formatting

Formatted strings, decimals and commas question

Formatted strings, decimals and commas question Question: I have a .txt file that I read in and wish to create formatted strings using these values. Columns 3 and 4 need decimals and the last column needs a percent sign and 2 decimal places. The formatted string will say something like "The overall attendance at Bulls …

Total answers: 2

How to convert voltage (or frequency) floating number read backs to mV (or kHz)?

How to convert voltage (or frequency) floating number read backs to mV (or kHz)? Question: I am successfully able to read back data from an instrument: When the read back is a voltage, I typically read back values such as 5.34e-02 Volts. When the read back is frequency, I typically read values like 2.95e+04or 1.49e+05 …

Total answers: 2

How to fix the number of decimals to 500 digits output in Python?

How to fix the number of decimals to 500 digits output in Python? Question: In the following example: import math x = math.log(2) print("{:.500f}".format(x)) I tried to get 500 digits output I get only 53 decimals output of ln(2) as follows: 0.69314718055994528622676398299518041312694549560546875000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 How I can fix this problem? Asked By: Psylife || Source Answers: You …

Total answers: 3

How to add thousand separator to numbers in pandas

How to add thousand separator to numbers in pandas Question: Assuming that I have a pandas dataframe and I want to add thousand separators to all the numbers (integer and float), what is an easy and quick way to do it? Asked By: DanZimmerman || Source Answers: When formatting a number with , you can …

Total answers: 6

numpy.savetxt- Save one column as int and the rest as floats?

numpy.savetxt- Save one column as int and the rest as floats? Question: The Problem So I have a 2D array (151 rows, 52 columns) I’d like to save as a text file using np.savetxt. However, I want the first column’s numbers to save as integers (1950, 1951, etc) while the rest of the data saves …

Total answers: 4

Convert float to string in positional format (without scientific notation and false precision)

Convert float to string in positional format (without scientific notation and false precision) Question: I want to print some floating point numbers so that they’re always written in decimal form (e.g. 12345000000000000000000.0 or 0.000000000000012345, not in scientific notation, yet I’d want to the result to have the up to ~15.7 significant figures of a IEEE …

Total answers: 7

Can you format pandas integers for display, like `pd.options.display.float_format` for floats?

Can you format pandas integers for display, like `pd.options.display.float_format` for floats? Question: I’ve seen this and this on formatting floating-point numbers for display in pandas, but I’m interested in doing the same thing for integers. Right now, I have: pd.options.display.float_format = ‘{:,.2f}’.format That works on the floats in my data, but will either leave annoying …

Total answers: 3

How to make Python format floats with certain amount of significant digits?

How to make Python format floats with certain amount of significant digits? Question: I want my Python (2.4.3) output numbers to have a certain format. Specifically, if the number is a terminating decimal with <= 6 significant digits, show it all. However, if it has > 6 significant digits, then output only 6 significant digits. …

Total answers: 3

Format / Suppress Scientific Notation from Pandas Aggregation Results

Format / Suppress Scientific Notation from Pandas Aggregation Results Question: How can one modify the format for the output from a groupby operation in pandas that produces scientific notation for very large numbers? I know how to do string formatting in python but I’m at a loss when it comes to applying it here. df1.groupby(‘dept’)[‘data1’].sum() …

Total answers: 9

Suppress Scientific Notation in Numpy When Creating Array From Nested List

Suppress Scientific Notation in Numpy When Creating Array From Nested List Question: I have a nested Python list that looks like the following: my_list = [[3.74, 5162, 13683628846.64, 12783387559.86, 1.81], [9.55, 116, 189688622.37, 260332262.0, 1.97], [2.2, 768, 6004865.13, 5759960.98, 1.21], [3.74, 4062, 3263822121.39, 3066869087.9, 1.93], [1.91, 474, 44555062.72, 44555062.72, 0.41], [5.8, 5006, 8254968918.1, 7446788272.74, 3.25], …

Total answers: 4