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

how to extract a cell value from a dataframe?

I am trying to extract a cell value from a dataframe, then why I always get a series instead of a value. For example: df_test=pd.DataFrame({'Well':['test1','test2','test3'],'Region':['east','west','east']}) df_test Well Region 0 test1 east 1 test2 west 2 test3 eas well="test2" region_thiswell=df_test.loc[df_test['Well']==well,'Region'] region_thiswell 1 west Name: Region, dtype: object I am expecting variable of region_thiswell is equal to

Read More
python

can someone help me figure out what is wrong with my code?

import os import zipfile import pandas as pd Function to find ZIP files with the relevant keywords (VTE, CLI, ART) def find_zip_files(month_folder_path): zip_files = {"vte": None, "cli": None, "art": None} List all files in the month folder for filename in os.listdir(month_folder_path): if "VTE" in filename and filename.endswith('.zip'): zip_files["vte"] = os.path.join(month_folder_path, filename) elif "CLI" in filename

Read More
python

Providing an IPython Interpreter During Development in a Hatch Project

I have a project using Hatch as a build system for pyproject. My pyproject.toml looks like this: [project] name = "demo" description = "Demo Project" version = "0.0.1" readme = "README.md" requires-python = ">=3.12" dependencies = [] [project.optional-dependencies] test = [ "pytest", "ipython", ] [build-system] requires = ["hatchling"] build-backend = "hatchling.build" [tool] [tool.hatch.envs.default] type =

Read More
python

Algo trading Drawdown calculations SettingWithCopyWarning:

I am trying to calculate maximum drawdown using closing price of a stock. STEP1: Imported the data and sliced that data in a new data frame df1 with date and closing price. df = pd.read_csv('BHEL.NS.csv') df['Date'] = pd.to_datetime(df['Date']) df1 = df[['Date', 'Close']] print(df1.head(n=15)) STEP2: Used the data to calculate rolling maxima (maxrollr) and calculate Drawdowns

Read More
python

How to Solve Extremely Ill-Conditioned Linear System of Equations Ax = b?

I am working on solving a system of linear equations with multiple variables. The system is of the form Ax=b, where the matrix A is extremely ill-conditioned. I have been struggling to find a stable solution for this problem. I have tried several numerical approaches, including genetic algorithms and other optimization methods, but I have

Read More
python

Problem with Empty credentials.json File in GitHub Actions

I’m having trouble with GitHub Actions while trying to integrate with the Google Sheets API. I’m attempting to save my Google Sheets credentials as a credentials.json file from repository secrets, but the file that gets created is always empty. This results in an error in my Python script when I try to use the credentials

Read More
python

Github Actions cannot find my poetry-installed dev dependencies and therefore cannot find the aws_cdk module when trying to call cdk deploy

I have a mangum python service with a cdk stack that I can deploy on my local box just fine. Here are my: pyproject.toml [tool.poetry] name = "dics-core-data-service" version = "0.1.0" description = "" authors = ["Clayton <clayton.stetz@gmail.com>"] readme = "README.md" package-mode = false [tool.poetry.dependencies] python = "^3.12" fastapi = "^0.115.0" uvicorn = "^0.31.0" python-dotenv

Read More
python

Simple JWT TokenRefreshView: response has two types

I’m having trouble accessing the data attribute on a Response object in Django Rest Framework after refreshing the access token. factory = APIRequestFactory() new_request = factory.post( "/api/token/refresh/", {"refresh": refresh_token}, format="json", ) new_request.META["CONTENT_TYPE"] = "application/json" refresh_view = TokenRefreshView.as_view() refresh_response = refresh_view(new_request) print(type(refresh_response)) refresh_response.data["message"] = "Token refresh successful" When I run this code, the print statement correctly

Read More
python

How do I plot matrixes of data in 3d using Python?

I am working with OCT scans and I have 3d matrixes of data, the background has the value 0.0 and the rest is aligned in the middle. How my current data looks in 2d plotting This image is an example of what I currently have, with the following shape/format Tensor [25, 496, 512] How do

Read More
python

SQLAlchemy hangs when sending ALTER TABLE

I’m trying to add a column to a PostgreSQL table with SQLAlchemy. I read on a couple threads that the simplest way to do this is to send plain SQL rather than modifying the Table object. My query is really basic: import sqlalchemy engine = create_engine("postgresql://user@host:port/db") query = sqlalchemy.text("alter table schema.table add column if not

Read More