formatting

How to convert user input date format to a different format on output in Python

How to convert user input date format to a different format on output in Python Question: I have a code where the date is an input converted to a date: InvDateStr = input("Enter the invoice date (YYYY-MM-DD): ") InvDate = datetime.datetime.strptime(InvDateStr, "%Y-%m-%d") I would like to later output this date in the format of "DD-Mon-YY" …

Total answers: 2

How do I format text using a variable?

How do I format text using a variable? Question: Basically, I want to be able to ask a question like "What colour do you want?" and then make it so that based on the answer it will set a variable and be usable in formatting. So something like this: print("33[1;35m33[1;4m What colour would you like …

Total answers: 2

Filtering dataframe based on string formatting in pandas

Filtering dataframe based on string formatting in pandas Question: I need to filter my dataframe based on dates, formatted as "%d-%m-%Y". I don’t know which columns meet this criteria, there might be more than one column meeting this condition. How can I tackle this problem? import pandas as pd df = pd.DataFrame( { "Name": [‘A’, …

Total answers: 2

xlwings find specific char text start and end position and format it

xlwings find specific char text start and end position and format it Question: I have multiple excel files with 12 sheets in each file. So, in each sheet, I have a fixed text like below – "Project has been blocked" So, I would like to do the below a) Find the text "Project has been …

Total answers: 1

Format Python numpy array output

Format Python numpy array output Question: How do I get this code to always return 1 decimal for every element in the array? import numpy as np def mult_list_with_x(liste, skalar): print(np.array(liste) * skalar) liste = [1, 1.5, 2, 2.5, 3] skalar = 2 mult_list_with_x(liste, skalar) I.e.: [2.0 3.0 4.0 5.0 6.0] not [2. 3. 4. …

Total answers: 2

Fixing Python Bokeh Datetime Import Formatting

Fixing Python Bokeh Datetime Import Formatting Question: I’m exporting datasets from equipment logging software and am trying to use Bokeh (Python) as an interactive visual aide during analysis. Everything is working fine, except for the date/time which refuses to be imported in its current format (24/08/2022 01:40:32). I have data for every second for at …

Total answers: 2

python-pptx access table cell properties and apply it back during replace

python-pptx access table cell properties and apply it back during replace Question: I am trying to replace the table headers in powerpoint using python-pptx using the code below slides = [slide for slide in ip_ppt.slides] shapes = [] for slide in slides: for shape in slide.shapes: shapes.append(shape) def replace_text(replacements:dict,shapes:list): if shape.has_table: for row in shape.table.rows: …

Total answers: 2

Print random numbers on same line inside f string

Print random numbers on same line inside f string Question: I’m trying to generate random numbers onto the same line and I am having some issues with the formatting. I am trying to shorten my long code below into something more efficient code wise: import random randomnumber1 = random.randint(1,99) randomnumber2 = random.randint(1,99) randomnumber3 = random.randint(1,99) …

Total answers: 2