Код входного фрейма данных:
import pandas as pd
df = pd.DataFrame([{'Column1': '((CC ) + (A11/ABC/ZZ) + (!AAA))','Column2': 'XYZ + XXX/YYY'}])
Входной фрейм данных: -
+---------------------------------+---------------------------------+
| Column1 | Column2 +
+---------------------------------+---------------------------------+
| ((CC ) + (A11/ABC/ZZ) + (!AAA)) | XYZ + XXX/YYY |
+---------------------------------+---------------------------------+
Список ввода: -
list = [AAA,BBB,CCC]
Условия: -
'+' should remain as such (similar to AND condition)
'/' means split the data into multiple cells (similar to OR condition)
'!' means replace with other elements in the corresponding list (similar to NOT condition)
Из-за!знак, строка становится
+------------------------------------+---------------------------------+
| Column1 | Column2 +
+------------------------------------+---------------------------------+
| ((CC ) + (A11/ABC/ZZ) + (BBB/CCC)) | XYZ + XXX/YYY |
+------------------------------------+---------------------------------+
Пожалуйста, помогите мне разбить одиночный ряд на несколько строк, как показано ниже, используя Pandas
+---------------------------------+---------------------------------+
| Column1 | Column2 +
+---------------------------------+---------------------------------+
| CC + A11 + BBB | XYZ + XXX |
+---------------------------------+---------------------------------+
| CC + ABC + BBB | XYZ + XXX |
+---------------------------------+---------------------------------+
| CC + ZZ + BBB | XYZ + XXX |
+---------------------------------+---------------------------------+
| CC + A11 + CCC | XYZ + XXX |
+---------------------------------+---------------------------------+
| CC + ABC + CCC | XYZ + XXX |
+---------------------------------+---------------------------------+
| CC + ZZ + CCC | XYZ + XXX |
+---------------------------------+---------------------------------+
| CC + A11 + BBB | XYZ + YYY |
+---------------------------------+---------------------------------+
| CC + ABC + BBB | XYZ + YYY |
+---------------------------------+---------------------------------+
| CC + ZZ + BBB | XYZ + YYY |
+---------------------------------+---------------------------------+
| CC + A11 + CCC | XYZ + YYY |
+---------------------------------+---------------------------------+
| CC + ABC + CCC | XYZ + YYY |
+---------------------------------+---------------------------------+
| CC + ZZ + CCC | XYZ + YYY |
+---------------------------------+---------------------------------+