October 21, 2024
Chicago 12, Melborne City, USA
python

How to create dataframe with nested List of varying elements in Polars?

I am trying to create a dataframe from nested list that has varying elements in it. Eventually I will unnest/explode this but stuck at first stage as of now. Below is the sample data and code which is failing: import polars as pl pl.DataFrame({'title': ['a','b','x','y'], 'info': [['Email','Contact','State','City','Wesbsite','Source'], ['Email','Contact','State','City'], ['Email','Contact','State','City','Wesbsite'] ['Email','Contact','State'] ] }) Even this is

Read More
python

Page format changes during RTF to PDF conversion using pypandoc

I’m using pypandoc to convert an RTF file to a PDF, but I’m running into an issue where the page structure and formatting are altered during the conversion. It looks like the output PDF is being generated using LaTeX, and this changes the layout compared to the original RTF file. Here’s the code I’m using:

Read More
python

Singleton by arguments in dependency_injector python

Im using dependency_injector in python with fastapi, and I’d like to cache instances of classes by the parameters passed to them. Here’s my current code: from fastapi import FastAPI, Depends from dependency_injector import containers, providers from dependency_injector.providers import Factory from dependency_injector.wiring import inject, Provide, Provider class Service: def __init__(self, name: str): print(f"Called constructor for {name}")

Read More
python

Dates mismatch in DataFrame – Data alignment

I’m seeking assistance with a date mismatch issue in my pandas DataFrame. I appreciate any insights you can provide. enter image description here I’ve attached an image showing a subset of my DataFrame. The full DataFrame contains about 98 columns, with each pair of columns representing a stock’s dates and values. The issue I’m facing

Read More
python

Updating to Spyder to 6.0.1 – Chosen Path already exists Error

Earlier today i got a pop-up stating Spyder can be updated to 6.0.1. When i try to update it, I get the following error message: The folder exists and but i am hesitant to delete it, as far as i can tell the current Spyder version is installed there. I installed spyder initially with Anaconda,

Read More
python

Why is my code not running correctly after the 'except' block

import json if __name__=='__main__': try: with open('input.json','r') as f: data=json.loads(f.read()) output=",".join([*data[0]]) for obj in data: output += f'\n{obj["Name"]},{obj["age"]},{obj["birthyear"]}' with open("output.csv","w") as f: f.write(output) except Exception as ex: print(f'eror:{str(ex)}') it shows eror: PS C:\Users\DELL> & C:/Users/DELL/AppData/Local/Programs/Python/Python312/python.exe "c:/Users/DELL/Desktop/python/project/New folder/password generator/main.py" File "c:\Users\DELL\Desktop\python\project\New folder\password generator\main.py", line 7 output=",".join([*data[0]]) ^^^^^^ SyntaxError: expected 'except' or 'finally' block PS C:\Users\DELL> I

Read More
python

ODE's not being solved because of a data mismatch in python. I have tried several approaches but keep getting the same error, what's wrong?

I am trying to use python to solve a set of ode’s for an electrical engineering project I am working on. In this project I am trying to solve a set of ODE’s in order to get the transfomer hotspot temperature against time for a day. I have a data frame showing the hourly total

Read More
python

How to ensure that the next available time slot is found immediately after the previous appointment finishes, without any unnecessary gaps

https://colab.research.google.com/drive/1hgG3N7Z7lLiYsmKclxfIGFAN5GXPbVlW?usp=sharing After the first appointment block from 09:00 to 09:50 (including the "blood test" and "x-ray"), the second user’s "blood test" starts from 09:50, which doesn’t make sense because there was already a "blood test" booked from 09:00 to 09:20. You need to sign in to view this answers

Read More
python

How to use timeout in Twitchio?

I tried to give the user to timeout. In the Twitchio.dev documentation, I found that the User class has the timeout_user command, but I don’t understand how to use it. I found the following solution on the Internet: ctx.channel.timeout(ctx.author.name , time, reason) but this does not work because the timeout is not contained in the

Read More
python

Vision Transformer Model not generalizing well on independent validation dataset

I am training a Wave Vision Transformer model. The code for the Wave_ViT is available on the below link. https://github.com/YehLi/ImageNetModel/blob/main/classification/wavevit.py I did not change the code for wave_ViT.py and torch_wavelets.py file. The only change I made is in the pipeline of how to provide data to model. My original dataset involves around 38000 MRI images

Read More