Skip to content

Instantly share code, notes, and snippets.

@Richard-Barrett
Last active January 27, 2025 23:27
Show Gist options
  • Select an option

  • Save Richard-Barrett/d82ef151403e0703f9aa1959718daf39 to your computer and use it in GitHub Desktop.

Select an option

Save Richard-Barrett/d82ef151403e0703f9aa1959718daf39 to your computer and use it in GitHub Desktop.
Reattribute GitHub EMU Account Post Migration
import pandas as pd
import argparse
def merge_data(mannequin_df, users_df, slug):
# Merge the dataframes on 'mannequin-user' and 'login'
merged_df = pd.merge(mannequin_df, users_df, left_on='mannequin-user', right_on='login', how='inner')
# Ensure that we only apply the transformation on non-null 'name' values
merged_df['name'] = merged_df['name'].apply(lambda x: f"{x.replace(' ', '-').lower()}_{slug}" if isinstance(x, str) else '')
# Select and reorder the columns to match the desired output
output_df = merged_df[['mannequin-user', 'mannequin-id', 'target-user', 'name']]
# Save the result to a new CSV
output_df.to_csv('merged_output.csv', index=False)
print("CSV file has been created successfully.")
if __name__ == '__main__':
# Set up argument parsing
parser = argparse.ArgumentParser(
description='This script merges mannequin user data with user data based on the mannequin-user and login fields. '
'It outputs a CSV file with the merged data, including a transformed name column.'
)
parser.add_argument('mannequin_df', type=str, help='Path to the mannequin CSV file')
parser.add_argument('users_df', type=str, help='Path to the users CSV file')
parser.add_argument('slug', type=str, help='Suffix to append to the name column')
# Parse the arguments
args = parser.parse_args()
# Load the CSV files
mannequin_df = pd.read_csv(args.mannequin_df)
users_df = pd.read_csv(args.users_df)
# Call the merge function with arguments
merge_data(mannequin_df, users_df, f"_{args.slug}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment