I have a csv file dataset that contains 170 columns, the first 5 columns contain unique identifiers (Platform, ID, date, length of call, name). The remaining columns 175 contain binary data covering 10 categories. I want to condense those columns so that the number of columns in my data frame is 15. Including an example below:
import pandas as pd
df1 = pd.DataFrame({'Platform': ['Telephone', 'Chat', 'Text'], 'ID': [1, 2,
3], 'Length': [1545,1532,1511], 'Name': ['andy', 'helen', 'peter'], 'Problem:
A':[0,1,0], 'Problem: B':[1,0,0], 'Problem: C': [0,0,1], 'Solution: A':
[0,1,0], 'Solution: B':[1,0,0], 'Solution: C': [0,0,1]})
The output is:
df.head()
ID Date Length\\
1 2015-10-16 1545
2 2015-10-09 1532
3 2015-10-13 1511
Name Problem: A Problem: B Problem: C Solution: A Solution: B Solution: C
andy 0 1 0 0 1 0
helen 1 0 0 1 0 0
peter 0 0 1 0 0 1
What I want the data frame to look like:
Platform ID Length Name Problem Solution
Telephone 1 1545 andy B B
Chat 2 1532 helen A A
Text 3 1511 peter C C
FYI this is not the full dataframe. There are a total of 170 colums that I would like to transform into 15.