0

I have this DataFrame, got from a group of same dataframe, but they have the same column name as total_inflow but I need change these name to indicate the different origin each other column as total_inflow_t1, total_inflow_t2, ...

So I have this:

In [227]: all = DataFrame([node_t1["total_inflow"], node_t2["total_inflow"], node_t3["total_inflow"], node_t4["total_inflow"], node_t5["total_inflow"]]).T Out[227]: total_inflow total_inflow total_inflow total_inflow total_inflow time 01/01/01 00:01:00 0.0085 0.0040 0.0002 0.0001 0.0001 01/01/01 00:02:00 0.2556 0.1669 0.0590 0.0012 0.0001 01/01/01 00:03:00 0.9935 0.7699 0.3792 0.0283 0.0002 01/01/01 00:04:00 1.3873 1.2879 0.8767 0.1614 0.0011 

so I need to get this:

Out[227]: total_inflow_t1 total_inflow_t2 total_inflow_t3 total_inflow_t4 total_inflow_t5 time 01/01/01 00:01:00 0.0085 0.0040 0.0002 0.0001 0.0001 01/01/01 00:02:00 0.2556 0.1669 0.0590 0.0012 0.0001 01/01/01 00:03:00 0.9935 0.7699 0.3792 0.0283 0.0002 01/01/01 00:04:00 1.3873 1.2879 0.8767 0.1614 0.0011 
1
  • if one of these answers solved your problem please accept it by clicking the check mark on the left of it. Commented May 15, 2017 at 13:54

2 Answers 2

1

This is a more generic solution. It will add a suffix to all the columns.

df.columns = ['{}_t{}'.format(k,i+1) for i,k in enumerate(df.columns)] 
Sign up to request clarification or add additional context in comments.

Comments

0

after you create your dataframe all, update the column names with:

all.columns = ['total_inflow_t1', 'total_inflow_t2', 'total_inflow_t3', 'total_inflow_t4', 'total_inflow_t5'] 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.