Home > front end >  Python: Add row into pandas dataframe with array as column value instead of multiple rows?
Python: Add row into pandas dataframe with array as column value instead of multiple rows?

Time:04-19

I want to handle with a table of following form:

example = {'Assumptions': 1, 'Index': 5, 'Proposition': '¬p∧ ¬ (¬p)', 'Premisses': [4, 3], 'Rule': '∧I'}

The command

example = pd.DataFrame(example)

gets:

   Assumptions  Index Proposition  Premisses Rule
0            1      5  ¬p∧ ¬ (¬p)          4   ∧I
1            1      5  ¬p∧ ¬ (¬p)          3   ∧I

but my aim is to get some table of following form:

   Assumptions  Index Proposition  Premisses        Rule
0            1      5  ¬p∧ ¬ (¬p)          [3, 4]   ∧I

Is their a way to do that?

CodePudding user response:

You could wrap it in a list first, then construct the DataFrame:

df = pd.DataFrame([example])

Output:

   Assumptions  Index Proposition Premisses Rule
0            1      5  ¬p∧ ¬ (¬p)    [4, 3]   ∧I
  • Related