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

Best platform for data analysis with python

I am a CompSci Graduate and I have a strong intrest in Data Science/Analysis. I have completed an IBM certification(25 Hours) and it was with Jupyter Notebook. Now I am also doing a project from coursera which is also using Jupyter Notebook. I was thinking that in a real world scenario(e.g. Freelancing) Jupyter Notebook (Or

Read More
python

Is it possible to build a custom tf-agent environment that return more trajectories?

I need to code a custom environment in tf-agents which run a fluid-dynamics simulation an apply action to it. I coded a basic environment that return an observation, and a reward then the agent apply one action. Now I need to "upgrade" this environment. Basically I want to divide the environment into N pseudo-environment. Each

Read More
python

How to run Vosk on GPU?

I tried to run the code from here: https://github.com/alphacep/vosk-api/blob/master/python/example/test_gpu_batch.py but got: C:\Users\user\PycharmProjects\vosk-test\.venv\Scripts\python.exe C:\Users\user\PycharmProjects\vosk-test\main.py Traceback (most recent call last): File "C:\Users\user\PycharmProjects\vosk-test\main.py", line 16, in <module> model = BatchModel("vosk-model-en-us-0.42-gigaspeech") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\user\PycharmProjects\vosk-test\.venv\Lib\site-packages\vosk\__init__.py", line 243, in __init__ raise Exception("Failed to create a model") Exception: Failed to create a model Process finished with exit code 1 How to run

Read More
python

Python 2d list initialization

#!/usr/bin/env python BOARD_SIZE = 8 # square gaming board NOTHING = '.' SOMETHING = 'K' board = [[NOTHING] * BOARD_SIZE] * BOARD_SIZE # indexing: (row, col) board[0][0] = SOMETHING for row in board: for c in row: print(c, end='') print() Now that I was expecting: $ nano cownway.py &&./cownway.py K....... K....... K....... K....... K....... K.......

Read More
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