iterating through a column in dataframe and creating a list with name of the column + str

2024/7/7 6:28:18

I have a dataframe with 2 coulmn, i want to iterate through the column headers, use that value and add a string to it and use it as the name of a list.

rr

resampled=pd.DataFrame() resampled['RAT']=dd1['RAT'] resampled['SAT']=dd1['SAT'] rr=resampled-resampled.shift(1)

for ind, column in enumerate(rr.columns):name=column+'stuck'
name=[]    
print(name)

I want to get 2 list with names RATstuck SATstuck

THank you!

Answer

have you tried list comprehension?

[x+'stuck' for x in rr.columns]
https://en.xdnf.cn/q/120376.html

Related Q&A

Python multiple inheritance name clashes [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.Questions asking for code must demonstrate a minimal understanding of the problem being solved. Incl…

How to read multiple txt file from a single folder in Python? [duplicate]

This question already has answers here:How to open every file in a folder(8 answers)Closed 3 years ago.How can I read multiple txt file from a single folder in Python?I tried with the following code b…

Time Changing Without Clicking Button

The following code works fine as long as the time in the spinbox does not change. What I want is to do the set the time for a break. The first time it works perfectly but after that if I change the val…

Avoid `logger=logging.getLogger(__name__)` without loosing way to filter logs

I am lazy and want to avoid this line in every python file which uses logging:logger = logging.getLogger(__name__)In january I asked how this could be done, and found an answer: Avoid `logger=logging.g…

Find all directories and files of your laptop [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 8…

How to format and write excel using pandas

Lets assume that we have nested python dictionaries which should be written in single excel sheet file. Following are sample dictionaries which can be used. Car = [{"carbmodel": "Model A…

Openpyxl is unable to read after modifying

Requirement : 1.create a gui using Tkinter 2.Update the excel by fetching values from Tkinter entry widget 3.Read another sheet of the same workbook 4.plot graph using inside the Tkinter window.Prob…

Rounding datetime based on time of day

I have a pandas dataframe with timestamps shown below:6/30/2019 3:45:00 PMI would like to round the date based on time. Anything before 6AM will be counted as the day before. 6/30/2019 5:45:00 AM -&g…

Scraping Project Euler site with scrapy [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

Python date function bugs

I am trying to create a function in python which will display the date. So I can see the program run, I have set one day to five seconds, so every five seconds it will become the next day and it will p…