A Matrix: T

Photo by Miguel from Pexels

Pandas has being having a swell week. “It appears someone has been reading my help documentation”, pd thought out loud. Just then the from_dict attribute is called to create a dataframe for DataGist.

The dataframe structure looked kinda off, pd thought. Was it how the dataframe was created? Would it be easier to have a list out of the dict, create a df as dataframe is commonly called and append? Efficiency is key here…DE calls pd helpline…🙂

Now and again someone wants to change the structure of the dataframe. This is to help achieve a particular view instead of having data_gist_df[0][‘season’], the DE can call data_gist_df[‘season’]

Any idea on how this can be fixed? Some googling and StackOverflow options seem to be just a lot for a simple transpose. Oh, wait! Pandas package has a transpose attribute. Awesome sauce!!!!

data_gist_df.transpose() to the rescue.

Author screenshot showing how transpose works

The transpose() function as the name implies writes the columns as rows or rows as columns, all depending on what the user wants. One of the many cool attributes of pandas.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s