'How to change a list of synsets to list elements?

I have tried out the following snippet of code for my project:

import pandas as pd
import nltk
from nltk.corpus import wordnet as wn

nltk.download('wordnet')
df=[]
hypo = wn.synset('science.n.01').hyponyms()
hyper = wn.synset('science.n.01').hypernyms()
mero = wn.synset('science.n.01').part_meronyms()
holo = wn.synset('science.n.01').part_holonyms()
ent = wn.synset('science.n.01').entailments()
df = df+hypo+hyper+mero+holo+ent
df_agri_clean = pd.DataFrame(df)
df_agri_clean.columns=["Items"]
print(df_agri_clean)

pd.set_option('display.expand_frame_repr', False)

It has given me this output of a dataframe:

                             Items
0            Synset('agrobiology.n.01')
1               Synset('agrology.n.01')
2               Synset('agronomy.n.01')
3         Synset('architectonics.n.01')
4      Synset('cognitive_science.n.01')
5          Synset('cryptanalysis.n.01')
6    Synset('information_science.n.01')
7            Synset('linguistics.n.01')
8            Synset('mathematics.n.01')
9             Synset('metallurgy.n.01')
10             Synset('metrology.n.01')
11       Synset('natural_history.n.01')
12       Synset('natural_science.n.01')
13             Synset('nutrition.n.03')
14            Synset('psychology.n.01')
15        Synset('social_science.n.01')
16            Synset('strategics.n.01')
17           Synset('systematics.n.01')
18           Synset('thanatology.n.01')
19            Synset('discipline.n.01')
20     Synset('scientific_theory.n.01')
21  Synset('scientific_knowledge.n.01')

This can be converted to a list by just printing df.

[Synset('agrobiology.n.01'), Synset('agrology.n.01'), Synset('agronomy.n.01'), Synset('architectonics.n.01'), Synset('cognitive_science.n.01'), Synset('cryptanalysis.n.01'), Synset('information_science.n.01'), Synset('linguistics.n.01'), Synset('mathematics.n.01'), Synset('metallurgy.n.01'), Synset('metrology.n.01'), Synset('natural_history.n.01'), Synset('natural_science.n.01'), Synset('nutrition.n.03'), Synset('psychology.n.01'), Synset('social_science.n.01'), Synset('strategics.n.01'), Synset('systematics.n.01'), Synset('thanatology.n.01'), Synset('discipline.n.01'), Synset('scientific_theory.n.01'), Synset('scientific_knowledge.n.01')]

I wish to change every word under "Items" like so : Synset('agrobiology.n.01') => agrobiology.n.01 or Synset('agrobiology.n.01') => 'agrobiology' Any answer associated will be appreciated! Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source