©2017 KOEI GAMES CO., LTD. ALL RIGHTS RESERVED. KOEI and KOTO are registered trademarks and KOEI is a trademark of KOEI CORPORATION.
Q:

Python: splitting a string into an array of items inside of lists of lists

I have a large Pandas DataFrame that I’m converting to a CSV and then trying to generate HTML tables using the Python package Beautiful Soup. Inside of one of the Pandas columns, I have a string. It looks like:
[„I“, „am“, „unhappy“]

What I want to end up with is:
[[[„I“, „am“, „unhappy“]], [[„I“, „am“, „unhappy“]]]

I’ve tried using regex to separate each item in the string, but regex requires the entire string be delimited by specific characters, which isn’t an option since the string could be in any form. I’ve also tried regex to split the strings, but I’m not sure the syntax is correct. Ideally, I’d like to have a function that can handle these, as I have many additional columns of the same type of data and I’d like to be able to apply this function to the other columns.

A:

If all the strings are of one length, you can use
df[‚col‘] = df[‚col‘].str.split(‚,‘, expand=False)

(Extent1Extent2) P(*Extent1).print
print “ Extent3:“, P(*Extent3).print
print “ Extent4:“, P(*Extent4).print
print “ Extent5:“, P(*Extent5).print
print “ Extent6:“, P(*Extent6).print

 

Features Key:

  • Lands Between:
    Explore the Lands Between freely, where the river flows from the east to the west and the mountain range lies to the north. In the Lands Between, you can explore vast fields and numerous huge dungeons that intertwine, giving a sense of the great scale of the game.
    In addition to exploring, you can level up your equipment, create and compose magic, or invest gold to unlock new weapons and magic.
  • Elden Lord:
    Once you gain the necessary experience, make alliances with other players to become an Elden Lord.
  • Fantasy settings:

    • Lands Between:
      A region where the river flows from east to west. This region is where you can explore freely.
      This is the fantasy setting for the main fantasy game, where you won’t find typical fantasy elements as dragons and elves.
      However, this region has became a dangerous battleground with many thoughts from other worlds stuck here. Since the resource and knowledge are scarce here, it becomes a busy shipping area.
    • Shadow Ruins:
      Under the ruins of an ancient elven kingdom, there exists a secret that must not be discovered. There, the ruins of an old, forgotten hope reside…

    Features explained: