Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Learning Pandas
  • Table Of Contents Toc
Learning Pandas

Learning Pandas

By : Michael Heydt
4.2 (10)
close
close
Learning Pandas

Learning Pandas

4.2 (10)
By: Michael Heydt

Overview of this book

If you are a Python programmer who wants to get started with performing data analysis using pandas and Python, this is the book for you. Some experience with statistical analysis would be helpful but is not mandatory.
Table of Contents (14 chapters)
close
close
13
Index

Reshaping arrays


NumPy makes it simple to change the shape of your arrays. Earlier in this chapter, we briefly saw the .reshape() method of the NumPy array and how it can be used to reshape a one-dimensional array into a matrix. It is also possible to convert from a matrix back to an array. The following example demonstrates this by creating a nine-element array, reshaping it into a 3 x 3 matrix, and then back to a 1 x 9 array:

In [47]:
   # create a 9 element array (1x9)
   a = np.arange(0, 9)
   # and reshape to a 3x3 2-d array
   m = a.reshape(3, 3)
  m

Out[47]:
   array([[0, 1, 2],
          [3, 4, 5],
          [6, 7, 8]])

In [48]:
   # and we can reshape downward in dimensions too
   reshaped = m.reshape(9)
   reshaped

Out[48]:
   array([0, 1, 2, 3, 4, 5, 6, 7, 8])

Note

Note that .reshape() returns a new array with a different shape. The original array's shape remains unchanged.

The .reshape() method is not the only means of reorganizing data. Another means is the .ravel() method...

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Learning Pandas
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon