From 64ba3fe29546c028bbba340ef77ca03ad9ffa7fb Mon Sep 17 00:00:00 2001 From: Kilokem Date: Fri, 13 Sep 2024 17:47:19 +0200 Subject: [PATCH] Advanced --- AdvancedTutorials/1_Generators.py | 0 DataScienceTutorials/2_PandasBasics.py | 38 +++++++++++++++++++++-- DataScienceTutorials/cars.csv => cars.csv | 0 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 AdvancedTutorials/1_Generators.py rename DataScienceTutorials/cars.csv => cars.csv (100%) diff --git a/AdvancedTutorials/1_Generators.py b/AdvancedTutorials/1_Generators.py new file mode 100644 index 0000000..e69de29 diff --git a/DataScienceTutorials/2_PandasBasics.py b/DataScienceTutorials/2_PandasBasics.py index d1f0261..7d15a1b 100644 --- a/DataScienceTutorials/2_PandasBasics.py +++ b/DataScienceTutorials/2_PandasBasics.py @@ -16,13 +16,47 @@ brics.index = ["BR", "RU", "IN", "CH", "SA"] # Print out brics with new index values print(brics) +import os +pathofcars = os.path.abspath("cars.csv") #Another way to create a DataFrame is by importing a csv file using Pandas. Now, the csv cars.csv is stored and can be imported using pd.read_csv: # Import the cars.csv data: cars -cars = pd.read_csv('cars.csv') +print(pathofcars) +cars = pd.read_csv(pathofcars) # Print out cars print(cars) -#https://www.learnpython.org/en/Pandas_Basics \ No newline at end of file + +# Indexing DataFrames +# There are several ways to index a Pandas DataFrame. One of the easiest ways to do this is by using square bracket notation. +# In the example below, you can use square brackets to select one column of the cars DataFrame. You can either use a single bracket or a double bracket. The single bracket will output a Pandas Series, while a double bracket will output a Pandas DataFrame. + +# Print out country column as Pandas Series +print(cars['Size']) + +# Print out country column as Pandas DataFrame +print(cars[['Model']]) + +# Print out DataFrame with country and drives_right columns +print(cars[['YEAR', 'Make', 'Size']]) + +# Print out first 4 observations +print(cars[0:4]) + +# Print out fifth and sixth observation +print(cars[4:6]) + +#You can also use loc and iloc to perform just about any data selection operation. loc is label-based, which means that you have to specify rows and columns based on their row and column labels. iloc is integer index based, so you have to specify rows and columns by their integer index like you did in the previous exercise. + +# Print out observation +print(cars.iloc[2]) + +# Print out observations +print(cars.loc[[2,6]]) + +#List every TESLA from the list +teslas = cars[cars['Make'].values == 'TESLA'] +print(teslas) + diff --git a/DataScienceTutorials/cars.csv b/cars.csv similarity index 100% rename from DataScienceTutorials/cars.csv rename to cars.csv