English 中文(简体)
• 如何修改数据范围清单中所含内容?
原标题:How can modify dataframe list elements in a loop Python?

I have 2 dataframes in a list, I mean Intraday_Mape and Day_Ahead_Mape are dataframes. These dataframes contains hourly data but I want to change them into monthly data. When I am doing this, I want to use for loop because, I ll deal with more dataframes in the future.

report_dfs = [Intraday_Mape, Day_Ahead_Mape]

for i, _ in enumerate(report_dfs):
    report_dfs[i]=report_dfs[i].index.name =  Date 
    report_dfs[i]=report_dfs[i].resample( M ).mean().reindex(annual_date_range, fill_value = 0)
    report_dfs[i]=report_dfs[i].round(2)

When I print Intraday_Mape, I have still hourly data, it is not change. How can I achieve modified dataframes out of the for loop? I mean, when I print Intraday_Mape:

print(Intraday_Mape)

I got old one. How do I permanently change these datasets outside of the for loop?

问题回答

请说<代码>(报告_dfs[0]和(报告_dfs ***),以获取数据。 您没有实际修改指定的数据范围。 你正在篡改你编制的名单上的数据。 页: 1

you may want to try the for loop below (assuming report_dfs represents a list of data frames, not a list of strings):

for r in report_dfs:
    r = r.index.name =  Date 
    r = r.resample( M ).mean().reindex(annual_date_range, fill_value = 0)
    r = r.round(2)




相关问题
Memory Leak when using for(object in array) with iPhone SDK

I am running into some serious memory leaks in one of my applications I am building. I have a UINavigatonController that is inside a UITabBarview. Inside the NavView is a MKMap view. When you click an ...

PHP - Foreach loops and ressources

I m using a foreach loop to process a large set of items, unfortunately it s using alot of memory. (probably because It s doing a copy of the array). Apparently there is a way to save some memory with ...

as2 simple for loop not populating textbox

I have got an xml file that brings text into a flash movie in the form of an array, I need to population some textboxes and want to do this using a for loop. My loop look like this: for(var i=...

Weird acting loop in C#

Note: I added actual code snippets. Just scroll to end. // files is created by a OpenFileDialog. public void Function(String[] files, ...) { for(int i; i<files.Length; i++) { ...

iterating over map and array simultaneously in a for loop

I am having some trouble creating a for loop within a constructor to iterate over a map and an array at the same time. Here, it is indicated that this cannot be done with an enhanced for loop. I have ...

Are one-line if / for -statements good Python style?

Every so often on here I see someone s code and what looks to be a one-liner , that being a one line statement that performs in the standard way a traditional if statement or for loop works. I ...

Geocoding town names to their coordinates in a loop

I ve read similar posts, but still didn t find a solution for myself. Basically I have an array with countries+towns in PHP and I need to show them on the map with markers. Here is my code: function ...

热门标签