Mass replace text, then split the replaced text into multiple columns - from multiple csv files
Mostrar comentarios más antiguos
I have multiple csv files (Azure.csv, Blue.csv,...until 50th file) which has roughly this kind of data inside it:
ID, Duration, Team A, TeamAComposition, Team B, TeamBComposition
120404 3442 Azure Ae Bee Cee Dee Ee Blue Ef Gee Heij Ai Jei
302033 233 Azure Ae Bee Cee Dee Zet Cyan El Em En Ou Pee
...and so on
I would like to replace the team composition data into integers, so for example "Ae" will be replaced into "1", "Bee" will be "2", "Cee" into "3" and so on, and if possible convert those into 5 different new columns. So the new table is roughly like this
ID, Duration, Team A, AComp1, AComp2, AComp3, AComp4, AComp5, Team B, BComp1, BComp2, BComp3, BComp4, BComp5,
120404 3442 Azure 1 2 3 4 5 Blue 6 7 8 9 10
How can I do this? Thanks in advance.
6 comentarios
How do you go from 50 files to 5 tables? How is the grouping performed?
Is a team always composed of 5 members?
How is the mapping between team member names and numbers defined? Alphanumeric ordering?
Do you need help with the parsing of the files as well or have you got that sorted out? If not, please provide an example file.
NeverPerfecT
el 2 de Mzo. de 2018
Editada: NeverPerfecT
el 2 de Mzo. de 2018
Guillaume
el 2 de Mzo. de 2018
Most of what you want is easy (assuming you're on a recent version of matlab). The only complication is the lack of clear separation between the hero names in the team composition. Can this be changed? If not, is it guaranteed that there will never be full overlap between names?
e.g. you'd never come across ... Vengeful Spirit Assassin ... with a list of hero names containing 'Vengeful Spirit' and 'Spirit Assassin'. Otherwise, the line could be parsed either as ... Vengeful and Spirit Assassin or Vengeful Spirit and Asssassin ...
NeverPerfecT
el 2 de Mzo. de 2018
Guillaume
el 2 de Mzo. de 2018
A comma or any other separator not present in the names would remove any ambiguity indeed. It's possible to do the splitting without that separator but if there's a chance of the problem above, then an explicit separator is safer.
NeverPerfecT
el 3 de Mzo. de 2018
Editada: NeverPerfecT
el 3 de Mzo. de 2018
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!