rename

Rename columns with special signs and numbers

Rename columns with special signs and numbers Question: I have this df = pd.DataFrame( {‘st’: {0: ‘0’, 1: ‘>0-<10’, 2: ‘>=10-<20’, 3: ‘>=20’}} ) which yields st 0 >0-<10 >=10-<20 >=20 Each entry of [st] column represents a category. I would like to replace categories as follows: st 1 2 3 4 to achieve this, …

Total answers: 1

Batch Rename files with different Prefixes but same file type using python

Batch Rename files with different Prefixes but same file type using python Question: I am trying to rename my files incrementally with a counter starting at 1, which process them in a way depending on their prefix and same file extension. The directory has the following files examples: BS – foo.fxp BS – bar.fxp BS …

Total answers: 2

How to apply a script to all files in extension and change names accordingly?

How to apply a script to all files in extension and change names accordingly? Question: I have a script which does a certain transformation to a file. pipeline.load_files(‘txt’, ‘1.txt’) pipeline.transform(‘function0′,’file.jpg’, ‘1.txt’) pipeline.write(‘txt’, ‘result.txt’, opt={‘c’:None}) pipeline.score(function=’function1′, file =’file.jpg’) pipeline.score(function=’function2′, file =’file.jpg’) pipeline.write_csv(‘result.csv’) Now I want to use this script for all 100 txt files (1.txt-100.txt) in …

Total answers: 1

problem renaming files with os.rename and my counter

problem renaming files with os.rename and my counter Question: I’m trying to rename a load of files and using a counter which is loaded into the name. When I run the script the files in the folder get renamed to start at 02, and not 01. When i print the counter in the loop it …

Total answers: 2

Python 2.7 – Script to rename _TMP folder

Python 2.7 – Script to rename _TMP folder Question: I try to create a script to rename some folder with "_TMP" lasts digits import os basedir = ‘E:Test’ for fn in os.listdir(basedir): if not os.path.isdir(os.path.join(basedir, fn)): continue # Not a directory if ‘_TMP’ not in fn: continue # Invalid format firstname = fn.rpartition(‘_TMP’) os.rename(os.path.join(basedir, fn),os.path.join(basedir, …

Total answers: 1

Rename a variable each time the code is run (python)?

Rename a variable each time the code is run (python)? Question: I have a bit of python code that’s set to run on a schedule. (I think my problem is the same as if it were within a loop.) Let’s say that in its most basic form, the code snippet looks something like this: A …

Total answers: 3

Renaming column names from a data set in pandas

Renaming column names from a data set in pandas Question: I am trying to rename column names from a DataFrame that have space in the name. DataFrame (df) consists of 45 columns and the majority have spaces in the name. For instance: df.column.values [1] = ‘Date Release’, and the name should be changed to ‘Date_Release’. …

Total answers: 4

Rename column names of groupby and count result with Pandas

Rename column names of groupby and count result with Pandas Question: Given the following dataframe: import numpy as np df = pd.DataFrame({‘price’: np.random.random_integers(0, high=100, size=100)}) ranges = [0,10,20,30,40,50,60,70,80,90,100] df.groupby(pd.cut(df.price, ranges)).count() Out: price price (0, 10] 9 (10, 20] 11 (20, 30] 11 (30, 40] 9 (40, 50] 16 (50, 60] 7 (60, 70] 10 (70, …

Total answers: 3

ValueError: not enough values to unpack (expected 2, got 1) when splitting strings

ValueError: not enough values to unpack (expected 2, got 1) when splitting strings Question: I’ve tried to write a script that moves files from one folder to a selection of folders depending on what I have named the file. For example, ‘Physics – a’ would be moved from the ‘ts’ folder to ‘/Physics/Assignments’ in an …

Total answers: 4

Visual Studio Code (Mac OS) rename symbol doesn't work

Visual Studio Code (Mac OS) rename symbol doesn't work Question: When I right click and try to rename a variable name in Microsoft Visual Studio Code on Mac OS Mojave, it prompts for the new name, I hit enter and nothing happens. I have Python extension and Latex extension installed. Usually there are no errors, …

Total answers: 5