import numpy as np
import pandas as pd
# Create the dataframe
df = pd.DataFrame({
'A': [[0.99, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 0.25, 0.87]],
'B': [['a', 'b', 'c'], ['a', 'b', 'c'], ['a', 'b', 'c']]
})
# Convert the lists to numpy ndarray
df = df.applymap(np.asarray)
# Explode the dataframe
df = df.reset_index().apply(pd.Series.explode).set_index(['index', 'B'])
# Filter for rows whose value for column 'A' is less than 1
df = df[df < 1].dropna().reset_index().groupby('index').agg(list)
Начальный DataFrame:
A B
0 [0.99, 1.0, 1.0] [a, b, c]
1 [1.0, 1.0, 1.0] [a, b, c]
2 [1.0, 0.25, 0.87] [a, b, c]
Окончательный DataFrame будет выглядеть так:
B A
index
0 [a] [0.99]
2 [b, c] [0.25, 0.87]
Примечания:
Узнайте больше о pandas взорвать здесь .