Sitemap
Tech Talk With Alex

Tech Talk With Alex

At the end of the day, nothing is too hard to understand when it is explained simply. Making complex concepts easy for everyone to get smart!

Retrieving Data Information in Python- For beginners

3 min readOct 11, 2022
Press enter or click to view image in full size

There are tons of informations you can extract from a data sheet and here are some codes you can use to make out the best of it. I have been collecting these over a year, and recommend just testing all of them out.

#First make sure you imported all the libraries you need and the data sheet. Let´s keep it simple for now and import pandas and numpy as well as our datasheet. Everything in bold in the code-line means you have to insert the information actively.

import pandas as pd

import numpy as np

df = pd.read_csv(‘/content/YourDataSheet.csv’

# Get overall information of your data frame

  • df.info()
  • df.dtypes() or print(df.dtypes)
  • df.describe()
  • df.describe().T #Transposes columns and rows
  • df.describe(include=‘all’)
  • df.describe(include=[‘object’])
  • df.describe(include=[‘numeric’])
  • df[[‘Name of Column no 1’, ‘Name of Column no 2’]].describe()
  • df.columns
  • df.index
  • df.shape()
  • len(df) #get the number of rows in a data frame
  • len(your_column_name) #get number of rows of a column
    print(len(
    your_column_name))

# Extract more detailed information

  • print(df[“your_column_name”].quantile(0.995)) #99.5%
  • print(df[“your_column_name”].mean())
  • print(df[“your_column_name”].median())
  • df[“your_column_name”].value_counts().idxmax()
  • df[“your_column_name”].value_counts()
  • df[“your_column_name”]].value_counts().to_frame()
  • item_counts = df.groupby([‘your_column_name’]).size()
  • df[‘your_column_name’].unique() or df.your_column_name.unique()
    or len(df.
    your_column_name.unique())

#Locate Info by row & column

Get Tech Talk With Alex’s stories in your inbox

Join Medium for free to get updates from this writer.

Let´s understand the basics first of the code for selection and indexing.

Press enter or click to view image in full size

Now it´s time for you to try out these below codes.

  • data.loc[row selection, column selection]
  • df.iloc[0] #locate information in row 0
  • df.iloc[[0,1,2]] #locate information in row 0,1,2
  • df.iloc[2].your_column_name #locate data in row 2 and column ‘your_column_name’
  • df.iloc[:,6:] # We select all rows and all columns after the 6th

For the ones that want to try something more advanced, try this code-line.

Let´s suppose we have 3 different store types, a, b and c and of each of those we have tons of stores spread across Europe.
We know their Sales, Number of Customers and the Days they have been open. (For reference see the first tab in the picture below)

Let´s find out the average Number of Customers and Sales per store type.

We use the code-line…

df.loc[:, [‘Your_Column_Name1’, ‘Your_Column_Name2’ ,‘Your_Column_Name3’]].groupby(‘Your_Column_Name1,2 or 3’).mean()

..and will end up with the second tab in the picture below. Note those are just random means inserted.

Press enter or click to view image in full size

Enjoy trying out all the above codes!

Disclaimer: The author of this article assumes no responsibility or liability for any errors or omissions in the content of this site. The information contained in this site is with no guarantees of completeness, accuracy, usefulness or timeliness.

--

--

Tech Talk With Alex
Tech Talk With Alex

Written by Tech Talk With Alex

At the end of the day, nothing is too hard to understand when it is explained simply. Making complex concepts easy for everyone to get smart!