I want the equivalent of this pandas code in pyspark. The following pandas code generates the atable names and the indexes where the atable name is found:
import pandas as pd
df1 = pd.DataFrame({
'atable': ['Users', 'Users', 'Domains', 'Domains', 'Locks'],
'column': ['col_1', 'col_2', 'col_a', 'col_b', 'col'],
'column_type':['varchar', 'varchar', 'int', 'varchar', 'varchar'],
'is_null': ['No', 'No', 'Yes', 'No', 'Yes'],
})
df1_grouped = df1.groupby('atable')
# iterate over each group
for group_name, df_group in df1_grouped.groups.items():
print(group_name, df_group)
Output:
Domains Int64Index([2, 3], dtype='int64')
Locks Int64Index([4], dtype='int64')
Users Int64Index([0, 1], dtype='int64')
The spark output should look like this:
#+-------+--------------------+
#|atable | sources|
#+-------+--------------------+
#|Domains| [2, 3] |
#|Locks | [4] |
#| Users | [0, 1] |
#+-------+--------------------+