Before we continue onto Dataframes, I want to clear up something from the Series exercise. Note the line (from pandas import Series, DataFrame)
Using that line, I can call upon Series or DataFrame directly in my code
In this example below, I did not directly import the methods Series and DataFrame, so I when I tried x = Series() I go an error.
I had to use the full method name of pd.Series() for this to work.
DataFrames provide another level of data management for Python. Those of you who come from a more data driven background with appreciate DataFrames.
Let’s start by creating dictionary.
Now, pass the dictionary to the method DataFrame()
Note, now you have a table looking structure with named columns
You can call up a list of indexes or columns using the methods below:
DataFrame.info() will return a summary of your DataFrame
Head and Tail
Create a new DataFrame from a dictionary
If you want just see a few of the first elements, you can use the head() method
The tail() method does the last few. You can even choose how many rows you want.
The describe() method gives you some quick statistics on any numeric column
You can slice a DataFrame just as you would a list
Choose What to Display
DataFrames allow you to filter what rows to display by value or column
There is a lot more you can do with Series and DataFrame in pandas, and we will be covering them in later lessons. For now though, I think you have a general idea.
If you enjoyed this lesson, click LIKE below, or even better, leave me a COMMENT.
Last Lesson: Pandas Series
Next Lesson: Working with DataFrames
Return to: Python for Data Science Course
Follow this link for more Python content: Python