2

I have a list of DataFrame, which is read something like this

data = [pd.read_csv(f, index_col=None, header=None) for f in temp]
flow = pd.DataFrame(data)

If I print the flow I get an output of

[[....
[128 rows x 14 columns]]
[128 rows x 14 columns]]
.
.
[128 rows x 14 columns]]]

So this means that each of the [128 rows x 14 columns] has one index, I have 60 as such. What I wanted to do was to read another CSV file which contains one column of data (60 rows) which looks something like this

[1 1 1 ... 2 2 2 ... 3 3 3]

I can read this by doing

new_data=pd.read_csv(f_new, index_col=None, header=None)

Now my question is can I keep everything as it is and just add the new_data as extra index, which should show something like this:

[[....
0 1 [128 rows x 14 columns]]
1 1 [128 rows x 14 columns]]
2 1 .
3 2 .
4 2 [128 rows x 14 columns]]]

Is this possible?

2
  • Did you try: flow = flow.set_index([flow.index, new_data])? Commented Jun 20, 2016 at 8:43
  • @MaxU This seems to work can I name these two indexes? and also can you post this answer so that I can accept it? Commented Jun 21, 2016 at 0:40

1 Answer 1

3

Try this:

flow = flow.set_index([flow.index, new_data]).rename_axis(['idx_col1','idx_col2'])
Sign up to request clarification or add additional context in comments.

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.