rename

Rename result columns from Pandas aggregation ("FutureWarning: using a dict with renaming is deprecated")

Rename result columns from Pandas aggregation ("FutureWarning: using a dict with renaming is deprecated") Question: I’m trying to do some aggregations on a pandas data frame. Here is a sample code: import pandas as pd df = pd.DataFrame({“User”: [“user1”, “user2”, “user2”, “user3”, “user2”, “user1”], “Amount”: [10.0, 5.0, 8.0, 10.5, 7.5, 8.0]}) df.groupby([“User”]).agg({“Amount”: {“Sum”: “sum”, “Count”: …

Total answers: 6

Renaming multiple files in a directory using Python

Renaming multiple files in a directory using Python Question: I’m trying to rename multiple files in a directory using this Python script: import os path = ‘/Users/myName/Desktop/directory’ files = os.listdir(path) i = 1 for file in files: os.rename(file, str(i)+’.jpg’) i = i+1 When I run this script, I get the following error: Traceback (most recent …

Total answers: 8

Rename columns in Pandas based on a dictionary

Rename columns in Pandas based on a dictionary Question: I have a pandas DataFrame and I would like to rename the columns based on another DataFrame that I plan to use as dictionary. For example, the first DataFrame is: AAA BBB CCC DDD index 1 1 2 3 4 2 5 6 7 8 and …

Total answers: 3

Python recursive file renaming

Python recursive file renaming Question: I am pretty new to python and I am attempting to create a python script that is able to recursively rename every file in a directory including subdirectories. But every time I run the script I’m getting the error OSError: [Errno 2] No such file or directory The directory contains …

Total answers: 2

Python: Rename duplicates in list with progressive numbers without sorting list

Python: Rename duplicates in list with progressive numbers without sorting list Question: Given a list like this: mylist = [“name”, “state”, “name”, “city”, “name”, “zip”, “zip”] I would like to rename the duplicates by appending a number to get the following result: mylist = [“name1”, “state”, “name2”, “city”, “name3”, “zip1”, “zip2”] I do not want …

Total answers: 8

Convert row to column header for Pandas DataFrame,

Convert row to column header for Pandas DataFrame, Question: The data I have to work with is a bit messy.. It has header names inside of its data. How can I choose a row from an existing pandas dataframe and make it (rename it to) a column header? I want to do something like: header …

Total answers: 6

How to rename PDF file, with texts extracted from the PDF file?

How to rename PDF file, with texts extracted from the PDF file? Question: I am trying to use Python to rename PDF file using part of the file content. Here is the situation. The PDF file is a commercial invoice, contains wordings "Commercial Invoice" and "Department". I want to rename the file to "Commercial Invoice" …

Total answers: 3

renaming a list of pdf files with for loop

renaming a list of pdf files with for loop Question: i am trying to rename a list of pdf files by extracting the name from the file using PyPdf. i tried to use a for loop to rename the files but i always get an error with code 32 saying that the file is being …

Total answers: 3

Rename Pandas DataFrame Index

Rename Pandas DataFrame Index Question: I’ve a csv file without header, with a DateTime index. I want to rename the index and column name, but with df.rename() only the column name is renamed. Bug? I’m on version 0.12.0 In [2]: df = pd.read_csv(r’D:DataDataTimeSeries_csv//seriesSM.csv’, header=None, parse_dates=[[0]], index_col=[0] ) In [3]: df.head() Out[3]: 1 0 2002-06-18 0.112000 …

Total answers: 9

Rename specific column(s) in pandas

Rename specific column(s) in pandas Question: I’ve got a dataframe called data. How would I rename the only one column header? For example gdp to log(gdp)? data = y gdp cap 0 1 2 5 1 2 3 9 2 8 7 2 3 3 4 7 4 6 7 7 5 4 8 3 …

Total answers: 7