Skip to content

Commit 2e28b2d

Browse files
authored
showing one way to create dataframes from lists (inspirezonetech#139)
* showing one way to create dataframes from lists * updated list to dataframe using flake8 * updated list to dataframe tutorial * commented out pandas * commented out code not running * Update dataframe.py
1 parent af75c1d commit 2e28b2d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lists/dataframe.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# ------------------------------------------------------------------------------------
2+
# Tutorial: creating a dataframe from lists
3+
# ------------------------------------------------------------------------------------
4+
# Think of a dataframe as an excel spreadsheet. All it is is a two-dimensional structure consisting of rows and columns.
5+
# Here I'll show you how to create a datframe with three columns using a list of lists.
6+
# Remember a list is created using square brackets []. So list of lists is different lists all wraped in a square bracket i.e. [['Sophie'], ['Jade']]
7+
# PS: anywhere you see a step, remove the hashtag before the code and remove everything in the bracket (). This does not include step 2!
8+
# e.g. in your practice, copy only "import pandas as pd" not "# import pandas as pd (step 2)"
9+
10+
# Firstly, pip install pandas then import pandas as pd
11+
# pip install pandas (step 1)
12+
# import pandas as pd (step 2)
13+
# Creating a list of lists with two strings and an integer each
14+
list = [['Purple Hibiscus', 'Chimamanda', 2001], ['Things Fall Apart', 'Chinua', 1980]] # Step 3
15+
16+
# Storing the transformation from list to dataframe in a variable
17+
# df means dataframe but you can call your variable anything
18+
# df = pd.DataFrame(list, columns=['BookTitle', 'AuthorFirstName', 'YearPublished']) (Step 4)
19+
# df (step 5)
20+
21+
# There are different ways to create a dataframe from lists. This was just one of them!
22+
23+
# ------------------------------------------------------------------------------------
24+
# Challenge: get the right answer !
25+
# 1. Make your own list of lists
26+
# 2. Store it in another variable that is not called df
27+
# 3. Create a dataframe from it
28+
# ------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)