You can also add data using lists.
For example, you can pass in a list of lists, where each one represents a row of data. Use the keyword argument
columns to pass a list of column names.
df2 = pd.DataFrame([ ['John Smith', '123 Main St.', 34], ['Jane Doe', '456 Maple Ave.', 28], ['Joe Schmo', '789 Broadway', 51] ], columns=['name', 'address', 'age'])
This command produces a DataFrame
df2 that looks like this:
|John Smith||123 Main St.||34|
|Jane Doe||456 Maple Ave.||28|
|Joe Schmo||789 Broadway||51|
In this example, we were able to control the ordering of the columns because we used lists.
You’re running a chain of pita shops called Pita Power. You want to create a DataFrame with information on your different store locations.
Use a list of lists to create a DataFrame with the following data:
|Store ID||Location||Number of Employees|
We have filled in the information for the first two rows in
Add the code to create the 3rd and 4th rows, and the column names.