0

I have multiple dataframes (separated by n, then by s, then by m) like this, call it df1 for n = '239', s = 'male', m = 'is1':

Days    24hU       24hF     ...
1       1e-3       ....     ...
2       8e-4       ....     ...
5       6e-4       ....     ...
...     ....       ....     ...

All dataframes have the same first column 'Days' (which can be set as the index for each dataframe) with same values in the rows. I would like to have a combined dataframe that contains column headers:

Days    24hU_n1s1m1    24hU_n1s1m2    24hU_n1s1m3    ...    24hU_n2s2m6
1       1e-3           ...            ...            ...    ...
2       8e-4           ...
5       6e-4           ...
...     ...            ...

I have the following so far:

for n in ("239", ...):
    for s in ("Male", "Female"):
        for m in ("is1",...):
            df = pandas.read_csv("DF Files//"+n+"//CSVoutputFiles//"+s+"//"+m+".csv", sep=',',skiprows=1, nrows=300).set_index('Days')
1
  • What happens and what would you want to happen? Commented Dec 12, 2017 at 17:34

1 Answer 1

1

Something like this? (This sounds kind of like a data frame merge but that only works in pairs.)

# first set the index
df1 = df1.set_index("Days")
df1.columns = [c+"_suffix1" for c in df1.columns]
... # similarly for other dataframes
combined = pd.concat([df1, df2], axis=1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.