1

I'm trying to get the values in the 'Output' column split into separate rows:

Category Output
Car Doc, writeback
Car Trace, dataview

This needs to be:

Category Output
Car Doc
Car Trace
Car writeback
Car dataview

I've tried: new_df = auto_test_file.DataFrame(auto_test_file.Output.str.split('|').tolist(), index=auto_test_file.Region).stack()

but this gives the error:

AttributeError: 'DataFrame' object has no attribute 'DataFrame'

1 Answer 1

1
import pandas as pd
d = {'Category': ["Car", "Car"], 'Output': ["Doc, writeback", "Trace, dataview"]}
df = pd.DataFrame(data=d)
df_splitted = pd.DataFrame(columns = df.columns)
for i in range(len(df)):
    outputs = df['Output'][i].split(',')
    for j in outputs:
        df_splitted.loc[len(df_splitted)] = [df['Category'][i], j]
print(df_splitted)
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.