format

Formatting list of n-length in SQL friendly string

Formatting list of n-length in SQL friendly string Question: I want to be able to enter a list OF ANY LENGTH consisting of 6-digit GLs. Needs to be variable length list for future development. Reformatting: Add leading 0000s because old SAP just loves random extra zeros. Convert the list into the proper formatted string for …

Total answers: 1

What's wrong in this print's formatting? Why is it not alligned?

What's wrong in this print's formatting? Why is it not aligned? Question: While trying to solve an exercise, I tried to make the final print’s exhibition a bit better by using tab (t) inside the line. I tried it in another stance and it made the final result look like a table. Should I ditch …

Total answers: 2

How to check the string format of an entire column in Python using regex

How to check the string format of an entire column in Python using regex Question: I have Account Names which look like GH85036, LG95639, etc in a column. I want to check the format of the entire columns so I can edit the ones that don’t follow the format. This is my first time using …

Total answers: 1

Improve print readability of nested Frozenset

Improve print readability of nested Frozenset Question: The output of the code example below has terrible readability. The data I’d like to analyse is hidden within numerous frozenset({}) prints. A = frozenset(["A1", "A2"]) B = frozenset(["B1", "B2"]) C = frozenset(["C1", "C2"]) foo = {A, B, C} print(foo) # {frozenset({‘B1’, ‘B2’}), frozenset({‘C1’, ‘C2’}), frozenset({‘A1’, ‘A2’})} print(*foo) …

Total answers: 1

Microsecond do not work in Python logger format

Microsecond do not work in Python logger format Question: For some reason my Python logger does not want to recognize microseconds format. import logging, io stream = io.StringIO() logger = logging.getLogger("TestLogger") logger.setLevel(logging.INFO) logger.propagate = False log_handler = logging.StreamHandler(stream) log_format = logging.Formatter(‘%(asctime)s – %(name)s – %(levelname)s – %(message)s’,"%Y-%m-%d %H:%M:%S.%f %Z") log_handler.setFormatter(log_format) logger.addHandler(log_handler) logger.info("This is test info …

Total answers: 2

Using Python rjust(8) does not seem to work on last item in list

Using Python rjust(8) does not seem to work on last item in list Question: I have text file containing comma separated values which read and output again reformatted. 102391,-55.5463,-6.50719,-163.255,2.20855,-2.63099,-7.86673 102392,11.224,-8.15971,15.5387,-11.512,-3.89007,-28.6367 102393,20.5277,-62.3261,-40.9294,-45.5899,-53.222,-1.77512 102394,188.113,19.2829,137.284,14.0548,4.47098,-50.8091 102397,-24.5383,-3.46016,1.74639,2.52063,3.31528,16.2535 102398,-107.719,-102.548,52.1627,-78.4543,-65.2494,-97.8143 I read it using this code: with open(outfile , ‘w’) as fout: with open(infile) as file: for line in file: linelist …

Total answers: 1

How to sum price of human readable currency format?

How to sum price of human readable currency format? Question: I retrieve data from a website, the price column is 809.989K, 1.792M and I want to combine the numbers from the price column into a new column. My dataframe import pandas as pd data = { "price": ["809.989K", "1.792M"] } df = pd.DataFrame(data) df Desired …

Total answers: 1

How to format dictionary.items , so that it will return 2 marks after comma?

How to format dictionary.items , so that it will return 2 marks after comma? Question: I have a excel sheet and I extract some values from the sheet. But some numbers extracted from the file sheet looks like: 3767.3999999999996 and it has to be: 3767,39. So just two decimals after comma. I Tried with this …

Total answers: 1