I have a large DataFrame with 50+ columns which I’m simplifying here below: I’m trying to find a) whether there are any instances of ‘—>’ in any of the cells across the DataFrame? b) if so where? (optional) So far I’ve tried 2 approaches this only works for strings not s…
Tag: python
sqlalchemy: AttributeError: type object ‘customer’ has no attribute ‘invoices’
I am new to sqlalchemy. I can create database tables by declarative mapping like this: This is fine. I added some data into both customer and invoice tables. So far so good. Next, I would try out automap_base on this existing database like this: When I ran the code, I got: AttributeError: type object ‘c…
transformers longformer classification problem with f1, precision and recall classification
I am replicating code from this page and I am getting F1, precision and recall to be 0. I got accuracy as shown by the author. What could be reason? I looked into compute_metrics function and it seems to be correct. I tried some toy data as below and precision_recall_fscore_support seems to be giving a correc…
Install pre-commit on package install in setup.py file
I would like, when I install my python package with pip install ., that the command pre-commit install be run as well as everything else in the setup file. Here is my setup.py file where I try to execute this: However, when I run this, pre-commit install does not get run. I’m mostly taking inspiration f…
converting a key value text file into a CSV file
I have a text file that needs to be converted into CSV file using pandas. A piece of it is presented in the following: Rows are cod,10, and cod,18 and the columns are 1, 2, 3,…, 15. Any idea? Regards, Ali Answer I use pandas to deal with the conversion, but vanilla Python to deal with some of aspects of
Python counting up (1+2+3 etc.) until input value
How to keep counting up (1+2+3) until user input value? This is my code so far, I can’t figure out how to keep increasing the value by one at a time… the goal should be e.g if input value was 2 to print 3 and if 10, 10 and 18, 21. Answer The problem with your code is you always
create an int column after dividing a column by a number in pandas
Assume that I have a panda data frame with a column that holds seconds. I want to create a new column that holds minutes. so I divide the sec column by 60. The problem that I have is that min column is not an integer anymore. How can I make it an integer? I have this code: I tried this,
create new column on conditions python
I have a ref table df_ref like this: I need to create a new column in another table based on ref table.The table like this: The output table df_org looks like: If any column value in col1 and col2 can find in ref table, it will use the ref col in ref table. If col1 and col2 are NULL, So
How to split words into different columns in dataframe?
I am new to coding , recently started learning to code. Currently I am stuck in the process to split a column. Please help me I have this dataframe and I want to split it into Really appreciate for taking your time and answering to my problem. PS: this is just an example of option symbol which is combination …
How many processors should be used with multiprocessing.Pool?
I am trying to use multiprocessing.Pool to run my code in parallel. To instantiate Pool, you have to set the number of processes. I am trying to figure out how many I should set for this. I understand this number shouldn’t be more than the number of cores you have but I’ve seen different ways to d…