How to create one-hot encodings for categorical variables?

Hello, I am currently working on a project where I have a dataset with categorical variables, and I need to create one-hot encodings for these variables. I have tried using pandas get_dummies() function to create these encodings, and while it works fine for smaller datasets, it becomes increasingly slow and memory-intensive as the size of the dataset increases. I am therefore looking for alternative ways to create one-hot encodings for categorical variables that are both fast and efficient in terms of memory usage. I would greatly appreciate any help or suggestions on how to tackle this problem in a more efficient manner. Thank you!

Example: