python-3.x

how to delete a duplicate column read from excel in pandas

馋奶兔 提交于 2021-02-10 05:41:05
问题 Data in excel: a b a d 1 2 3 4 2 3 4 5 3 4 5 6 4 5 6 7 Code: df= pd.io.excel.read_excel(r"sample.xlsx",sheetname="Sheet1") df a b a.1 d 0 1 2 3 4 1 2 3 4 5 2 3 4 5 6 3 4 5 6 7 how to delete the column a.1 ? when pandas reads the data from excel it automatically changes the column name of 2nd a to a.1. I tried df.drop("a.1",index=1) , this does not work. I have a huge excel file which has duplicate names, and i am interested only in few of columns. 回答1: If you know the name of the column you

Decorating a decorator

夙愿已清 提交于 2021-02-10 05:40:55
问题 I tried to do some argument modification on a decorator which decorates a function. The original code looks like @original_decorator(arg=some_object) def calculate(a, b): # complex business logic raise Exception() where original_decorator is responsible for exception handling. What I want to achieve is to do some temporary modification on some_object and restore it's property after function returned. And I've tried the following def replace_arg(arg, add_some_property): def decorator_wrapper

Visual Studio Code, Conda, and Python Environments (I cannot get it working)

↘锁芯ラ 提交于 2021-02-10 05:37:14
问题 I am setting up Visual Studio Code on my pc and am running into difficulties with the python environment I created and Visual Studio Code. However, when running some test code, I get an import error.. I installed Python 3.7.3 with miniconda to 'C:\Python37', and then created a clone of the base environment named 'sci' and installed some packages (numpy, pandas, matplotlib, scipy, scikit-learn) using cmd. I tested the install in cmd with commands as follows: conda activate sci python import

Pytest override fixture scope

廉价感情. 提交于 2021-02-10 05:35:27
问题 I pytest, we declare the fixture scope (function, module, class, session) at the fixture definition. Is it possible to override that scope at the usage of it in a test? So that I can have a default function-scope fixture, but some tests which are using it use it as module-scope? My concrete scenario is that I'm using parametrized tests, but I want my fixture to be used once over all parameters. Otherwise, the fixture is good to have function scope for all other tests. 来源: https:/

Pytest override fixture scope

有些话、适合烂在心里 提交于 2021-02-10 05:35:11
问题 I pytest, we declare the fixture scope (function, module, class, session) at the fixture definition. Is it possible to override that scope at the usage of it in a test? So that I can have a default function-scope fixture, but some tests which are using it use it as module-scope? My concrete scenario is that I'm using parametrized tests, but I want my fixture to be used once over all parameters. Otherwise, the fixture is good to have function scope for all other tests. 来源: https:/

stable-baseline with tensorflow issue

烂漫一生 提交于 2021-02-10 05:32:29
问题 It says: Stable-Baselines supports Tensorflow versions from 1.8.0 to 1.15.0, and does not work on Tensorflow versions 2.0.0 and above. So I tried to install "sudo pip3 install tensorflow==1.15.0" But I get the message: ERROR: Could not find a version that satisfies the requirement tensorflow==1.15.0 (from versions: 2.2.0rc1, 2.2.0rc2, 2.2.0rc3, 2.2.0rc4, 2.2.0) ERROR: No matching distribution found for tensorflow==1.15.0 I'm using: Ubuntu 20.04 LTS Python 3.8.2 pip 20.1.1 from .../python3.8

FastText recall is 'nan' but precision is a number

旧时模样 提交于 2021-02-10 05:31:20
问题 I trained a supervised model in FastText using the Python interface and I'm getting weird results for precision and recall. First, I trained a model: model = fasttext.train_supervised("train.txt", wordNgrams=3, epoch=100, pretrainedVectors=pretrained_model) Then I get results for the test data: def print_results(N, p, r): print("N\t" + str(N)) print("P@{}\t{:.3f}".format(1, p)) print("R@{}\t{:.3f}".format(1, r)) print_results(*model.test('test.txt')) But the results are always odd, because

Python lambda function to sort list according to dictionary

試著忘記壹切 提交于 2021-02-10 05:29:05
问题 The sample codes bellow retrieve all the runing procces and print them. They've bee written following the 3rd example here and final one from here. Problem is I cannot figure out why only the first one retrieves process sorted as desired. I think it is related to the lambda function construction. But the rightly running sample, the first one, seems to mix the local p variable of the for statement with the p.dict dictionary, making me get stuck. First Sample: import psutil procs = [] for p in

How to check frequency in csv file on python?

让人想犯罪 __ 提交于 2021-02-10 05:27:43
问题 I have few doc in .csv - 20 000 record or more. Basically it's easy - something like that: numer,produkt,date 202,produkt A its sad,20.04.2019 203,produkt A its sad,21.04.2019 204,produkt A its sad,22.04.2019 etc I want to print info: A "produkt A its sad" appears 6 times A "produkt B" appers 3 times A "produkt C" appers 2 times Base on another answer on stack overflow I wrote: import csv from collections import Counter with open ('base2.csv', encoding="utf8") as csv_file: csv_reader = csv

How to check frequency in csv file on python?

本秂侑毒 提交于 2021-02-10 05:27:13
问题 I have few doc in .csv - 20 000 record or more. Basically it's easy - something like that: numer,produkt,date 202,produkt A its sad,20.04.2019 203,produkt A its sad,21.04.2019 204,produkt A its sad,22.04.2019 etc I want to print info: A "produkt A its sad" appears 6 times A "produkt B" appers 3 times A "produkt C" appers 2 times Base on another answer on stack overflow I wrote: import csv from collections import Counter with open ('base2.csv', encoding="utf8") as csv_file: csv_reader = csv