Data Structures in Pandas
Lesson 2 of 19 in Coddy's Pandas Analytics course.
Pandas uses two types of data structures: series and dataframes.
- A series in Pandas is like a one-dimensional array that holds any data type. For example, a series could be a list of integers
[4, 3, 8, 5]. - A dataframe is a two-dimensional data structure, like a table with rows and columns. Picture a spreadsheet or an SQL table. For instance, a DataFrame could be a collection of series (columns) such as name, age, and height.
Getting comfortable with Series and DataFrame will help you get the most out of Pandas.
To create a series use the following:
import pandas as pd
temp = pd.Series([1, 2, ,3])Every column in a dataframe is a series object.
To convert a dictionary to a dataframe it must be in the right format:
data = [{"col1": 22000,'col2': 1500.0},
{"col1": 25000,'col2': 3000.0},
{"col1": 23000,'col2': 2500.0}]
df = pd.DataFrame(data)There are other formats as well that are valid.
Challenge
EasyCreate a function named dataframe_creator that receives data, creates a dataframe from the data, and finally prints the dataframe.
To print a dataframe, write: print(df).
Try it yourself
import pandas as pd
def dataframe_creator(data):
# Write code hereAll lessons in Pandas Analytics
4Data Analysis with Pandas
Descriptive StatisticsGrouping and Aggregating DataDifferent AggregationsMerge & Concat2Working with the DataFrame
Understanding DataFramesAccessing DataData Cleaning - Missing dataData Cleaning - More tools3Data Manipulation with Pandas
Return Requested ResultFilter DataAdd & DeleteModify DataModify StringsCustom Modifications