Blogs

Blogs

Python API Tutorials| Getting Started with API’s

API is the acronym for Application Programming Interface, which is a software middleman that allows two applications to interact with each other. Each time we use an application like Facebook, send an instant message or check the weather on your phone and any other apps, you’re using an API.  Another example of an API is when you use an application on your mobile phone. The application connects to the Internet and sends data to a particular server. The server will redeem that data, demystify it, and send it back to your phone. The application then interprets that data and presents you with the information you need in a readable way .In this article, you will learn the basics of Python API and the step-by-step process to get started with APIs. How to Get Started with Python APIs To use an API, you have two options. The first option is to authenticate and the second option is not to authenticate and it depends on the kind of API you’re working with. We will demonstrate with two different examples. For us to get started with getting data or pulling data via the API, we will use a particular library in Python known as the Requests Library. This library is a standard package for making HTTP Requests in Python. There are other libraries for making HTTP Requests such as httplib, urllib, httplib2, treq. We can install Requests using the command; pip install requests conda install requests We also have different standard HTTP Methods;GET; to request data from the server. POST; to submit data to be processed to the server. PUT: Update an API resource DELETE: Delete an API resource A request is also made up of different parts: The method – these are the methods which we just discussed now and theyare the GET, POST, PUT and DELETE The Endpoint – when sending a request to the server, we have an endpoint known as the URL which we used for communicating to that server. The headers – The headers in a request are used to provide information about the request context so the server can know how to tailor our response such as the content type = application/JSON, authentication keys, and so on. The data/body – The data/body is usually used in both POST and PUT, with this, we can parse in the credentials we want to use to authenticate with the server. We must also not forget the status code returned after we sent our request. This status code helps in knowing if our request was successful or not. Examples of these different status codes are; 200(Ok), 201(Created), 404(Not found), 401(Unauthorized), 500(Internal Server Error) etc.   Getting the Data We’ll demo this with two different options we mentioned earlier which is getting data with Authentication or not, we will use these two APIs to implement this: IPify – a free API that allows you to get your current IP address(No Authentication) Google Calendar – An API used for tracking events and more(With Authentication) No Authentication We will use Ipify API with our Requests library to get data. With this API, we will observe that we don’t need any credentials to perform authentication before we can use the API.  The reason for this is that the API is an open one which makes it not require authentication. Sample API Request: #import the request library import requests #we then use the GET methods along with the requests library to retrieve data from the ipify server data= requests.get(‘https://api.ipify.org?format=json’) #we now convert our response data to json json_response=data.json() #we also extract our values we want it to return back to us. my_ip=json_response[‘ip’] #Then print our result print(my_ip) With Authentication To implement this, we will use the Google Calendar API. To get started, we need to create a new project under the google developer account by using this URL https://console.cloud.google.com and then set our details under Oauth Consent screen and Credentials tab. After you have completed the whole setup, we will download the credentials.json from the console page and use that to authenticate with the server. We will write a code to retrieve our calendar events after we have gained access to the API. Sample code #import the libraries needed from __future__ import print_function import datetime import os.path from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request from google.oauth2.credentials import Credentials # If modifying these scopes, delete the file token.json. SCOPES = [‘https://www.googleapis.com/auth/calendar.readonly’,’https://www.googleapis.com/auth/calendar.readonly’,’https://www.googleapis.com/auth/calendar’,’https://www.googleapis.com/auth/calendar.events.readonly’,’https://www.googleapis.com/auth/calendar.events’] #we create an empty list all_events=[] #we create a function main which has all our functionality def main(): creds=None #this if statement checks if we have a token.json file in our working path if os.path.exists(‘token.json’): #when token.json exist, it execute function to recognize/authorize this user creds = Credentials.from_authorized_user_file(‘token.json’, SCOPES) #this is another if statement which checks if we don’t have the credentials or the credentials has expired or not valid if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: creds.refresh(Request()) #this else is to perform an authentication with the server using our credentials.json file and the SCOPES we specified else: flow = InstalledAppFlow.from_client_secrets_file(‘credentials.json’, SCOPES) creds= flow.run_local_server(port=0) #After authenticating, it writes out our result which contains an access token and other details which we can use often in our project with open(‘token.json’, ‘w’) as token: token.write(creds.to_json()) #we then read in the token file which has the access token and use this with the build method to access our calendar events service = build(‘calendar’, ‘v3’, credentials=creds) now = datetime.datetime.utcnow().isoformat() + ‘Z’ #we use the service method to check our events using our primary calendarId events = service.events().list(calendarId=’primary’, timeMin=now, singleEvents=True, orderBy=’startTime’).execute() all_events.append(events) print(all_events) if __name__ == ‘__main__’: main()

Blogs

Problem-Solving Skills| Improve Your Problem-Solving Skills in 2021

Introduction -In our day-to-day activities, we are all faced with problems or challenges we must overcome for us to move ahead. Let’s define what a problem is. A problem is regarded as a situation unwelcomed or harmful that needs to be dealt with. It can also be a question raised for inquiry, consideration, or solution. Problem-solving skill is highly essential for survival. This article will guide you on how to improve your problem-solving skills. Let’s dive right in.  What is problem-solving? It is raining and you have to go to the mall down the road to buy groceries. How do you get to the mall without being beaten by the rain? You can pick up an umbrella and rush down to the mall. On the other hand, you can decide to drive down in your car to the mall. That’s two solutions to a problem. You are free to go with the one that suits you. Problem-solving is an act of defining a problem, identifying, finding the root cause, prioritizing, and finding solutions to a problem. In simple terms, problem-solving is providing solutions to challenges or problems. Is problem-solving a skill? Problem-solving is a soft skill which like other skills, can be learned through education or training. It is a skill you can develop when you accustom yourself to recurrent issues in your field or industry and by learning from professionals.  It is an essential skill in the workplace and also in daily life.  This skill helps you to navigate through the issues of life. Why is Problem Solving Skill Important?  Having problem-solving skills will not only help you in your workplace but also in your daily life. Human beings are created to solve problems. Problem-solving skills possessed by great scientists were the reason for the great inventions we enjoy today. Breakthroughs in Medicine, Engineering, business, law, and other fields are a result of people coming up with solutions to problems. Imagine Micheal Faraday (the father of electricity) did not invent electricity! You’d probably not be reading this article on your device at the moment. Steps in Problem-solving Here, we will discuss the effective steps to take when you are solving problems. It’s important to follow these steps in the correct order if you want to solve a problem effectively. We’d be discussing five steps you must take to solve a problem. STEP 1: Identify and Define the problem This is the first step in problem-solving. This is the most important and the foundation of problem-solving. When you identify the problem, you are halfway to the solution. This is where you have to separate fact from opinion; ensure your statements are backed up with data.  Find out the root cause of the problem and not just the symptoms. Here you can ask the following questions: What is the problem? when did the problem start? STEP 2: Generate Possible Solutions The next step is to come up with different solutions. Brainstorming is one of the ways you can use it to generate solutions. A brainstorming session is where you generate lots of ideas both the ones that will make it to the final stage and those that you will have to discard. The brainstorming session is not where you evaluate the solutions you come up with. An important thing to keep in mind while brainstorming is “quantity over quality”. The more solutions you come up with, the higher the chances of having the best solution. You can brainstorm individually or in teams although having a brainstorming session with your teammates is preferable. STEP 3: Decide on a Solution After you have generated possible solutions, now is the time for you to sieve your solutions. You have to separate the wheat from the chaff. During your brainstorming session, you must have come up with solutions that cannot be implemented but couldn’t discard them because that’s not the aim of brainstorming. This step is where you analyze and select the best solution for the problem. You must have considered factors such as cost, resources, and timeliness while going for the solution you considered to be the best. STEP 4: Implement the solution Now that you’ve decided on a solution, this is the time to implement the solution. You have to act on and execute the solution you chose. It will be a total waste of time if you do not implement the solution you chose after going through the previous steps. STEP 5: Evaluate the results This is the final step in problem-solving and this is where you carefully evaluate your results.  You can do this after some weeks or months of implementing your solutions. For better evaluation of your results, ask the following questions: Did any new problems arise as a result of this solution? Are there possibilities that the solved problem will return? Problem-Solving Tools Fishbone Diagram- This is also called cause and effect or Ishikawa diagram and it is a visualization tool used in problem-solving. From its name, it takes the shape of a fish skeleton.  It is used to identify the root cause of a problem. The root problem is placed as the fish’s head and the causes project to the left, representing the bones of the skeleton. The ribs which branch off the back represent major causes while the sub-branches branch off of the causes and represent root causes. Flowcharts- A flow chart is a simple diagram that maps out a process so you can easily communicate it to your teammates. You can use a flowchart to show the operations and sequences needed to solve a problem. See a flowchart as the blueprint of a design you have created for solving a problem. Mind maps– A mind map is a useful tool in problem-solving as it helps you visually represent and structure your thoughts. It allows you to visualize problems and see the bigger picture at a glance, reduces stress, and awakens your creativity. How to Improve your Problem-solving Skills 1. Develop the right attitude Having a positive mindset and the right attitude while approaching problem-solving is key. In fact, do not see it as a problem rather as a challenge and an

Blogs

What is Tableau? Features and Uses

It is no news that data skills are high in demand in every sector of the business world. Businesses of all sizes, ranging from small to large are searching continuously for individuals that possess excellent data skills and the wise thing anyone would do is to jump on this data train heading to the future and equip him/herself with these skills that are high in demand.  One of these skills is maximum proficiency in Tableau. You might be wondering, “what is Tableau?”, “what does it do?”, “How does it work?”, etc. In this blog post, you will discover what this software is used for and basically how it works. What is Tableau? Besides the fact that it is a powerful and the fastest-growing data analysis tool in the Business Intelligence industry, it is the most secure and easy-to-use platform for analyzing your data. The great thing about this software is that it doesn’t require any kind of programming or coding skills to be able to understand and operate it. It can help anyone see and understand their data without the need for any advanced skills in data science. There are quite a few data visualization tools in the BI industry, but Tableau software seems to be the major buzzword. This is because it does not just analyze your data, it turns your data into golden insights that help make excellent business decisions. so don’t be surprised to see it leading in Gartner’s magic quadrant Are you still wondering why every organization wants someone with excellent skills in Tableau? I don’t think I am; the handwriting is on the wall. Who wouldn’t want someone that can operate a growth insight software? The software is a product suite with five (5) different tools; Tableau Desktop, Tableau Public, Tableau Online, Tableau Server, and Tableau Reader.     For a better understanding of data analysis in Tableau, these tools can be divided into two (2) groups:  Developer Tools: As you probably guessed, these are the tools used for development like creating dashboards and charts, or generating workbooks, reports, and visualizations. The tools in this category are Desktop and Public.  Sharing Tools: they are for sharing the visualizations, reports, dashboards, and workbooks created by the developer tools. Products in this category are Tableau Online, Server and Reader.  How does Tableau work?  The major function of the Tableau software is to extract data stored in various places. It can pull data from any platform imaginable. Take a moment to think about all the databases you know, ranging from simple ones like an excel or a pdf to complex ones like Oracle or even a database in the cloud like Amazon Web services (AWS), Google Cloud SQL, or Microsoft Azure SQL, name it; Tableau can extract data from all of them. How does it do that? It’s almost too easy. Once you launch the software, data connectors are available to help you connect to any database. Although, the number of supported data connectors can vary depending on the version of the software that you purchased and installed. The data that is pulled is extracted to Tableau Desktop, the software’s data engine. This is where the data analyst/engineer develops visualizations with the pulled data. The dashboards created are shared with the users as a static file that can be viewed using Tableau Reader. The data analyst can publish the data from Tableau Desktop to Server; therefore, users can access the files better from any location and on any device.     After reading all about Tableau, it’s features and uses, it is completely normal that you are feeling the need to become a master at this skill and launch your career on a whole different level. To download the tableau software to your computer, visit www.tableau.com. Not sure where to start? Cndro’s Tableau Training is just what you need if you want to understand Tableau and stand out among other professionals. It is a fully packed 8 weeks training that will take your proficiency in Tableau from zero to one hundred real quick. Click here to find out more about it. Once you start learning about this tool, you will realize how much of an eye-opener it is. 

Blogs

Automate AWS EC2’s Start and Stop using Lambda and CloudWatch

This post is a quick guide on how to automatically start and stop EC2 instances on Amazon Web Services (AWS). Amazon Elastic Compute Cloud (EC2) instances are like virtual servers on AWS. AWS is a cloud computing platform and EC2s help business subscribers run application programs on AWS. Let’s say, for example, a particular EC2 instance has been placed in your care by your organization. It needs to be turned on by midnight and turned off by 8 pm in the evening, which is quite absurd. You can choose to wake up every midnight to turn it on and cut your dinner date short to turn it off. You can also choose to dedicate 30 minutes only this one time to automate the entire process. In this post, we will quickly walk through how to automatically turn on and turn off these EC2s using Lambda and CloudWatch. All you need is an AWS Console root user or an IAM user with Lambda, CloudWatch and EC2 access. Oh!… and of course, 30 minutes of your time. STAGE 1: CREATE THE LAMBDA FUNCTIONS TO AUTOMATICALLY START/STOP EC2 INSTANCES Login to AWS Console: This is, of course, the first thing to do. Click the ‘Services’ drop-down menu and select Lambda under the Compute service. Choose the ‘Author from scratch’ option and a Basic Information form pops up with three fields: Function, Runtime, and Permissions. Put in your function name; “Start EC2” for example. Input your preferred programming language in the Runtime field. Python 2.7 was used in this case. In the Permissions field, you can choose to create a new role with basic Lambda permissions or use an existing role, if you already have one. To learn how to create a new role, check out our article on How to create an EC2 role. Hit that orange Create Function button to display a page where you can input your code. To create a Lambda function that automatically turns on an EC2 instance. Edit the code in the snippet below with the region and instance ID of the EC2 you are trying to automatically start. import boto3 region = ‘insert ec2 region’ instances = [‘insert ec2 instance ID’] ec2 = boto3.client(‘ec2’, region_name=region) def lambda_handler(event, context):     ec2.start_instances(InstanceIds=instances)     print(‘started your instances: ‘ + str(instances)) To create a Lambda function that automatically turns off an EC2 instance. The code is similar to the one in the snippet above, ‘start’ is just replaced with ‘stop’: import boto3 region = ‘insert ec2 region’ instances = [‘insert ec2 instance ID’] ec2 = boto3.client(‘ec2’, region_name=region) def lambda_handler(event, context):     ec2.stop_instances(InstanceIds=instances)     print(‘stopped your instances: ‘ + str(instances)) Our lambdas are ready, up next is CloudWatch. STAGE 2: CREATE CLOUDWATCH RULES TO TRIGGER THE LAMBDA FUNCTIONS Back to AWS Console.  Click the ‘Services’ drop-down menu and select CloudWatch under the Management and Governance service. In the CloudWatch dashboard, select Rules Hit the Create Rule button, select the ‘Schedule’ option and input the date and time you want your EC2 to start in the Cron expression field. In this study, the EC2 was set to start at 1:05 am every Monday to Thursday with a Cron expression of : 05 01 ? * MON-THUR* If you want to start your EC2 at 8 pm every working day of the week, for example, your Cron expression is going to be: 00 20 ? * MON-FRI* In the Targets section, select the Lambda function created earlier to turn on an EC2 instance. Hit the Configure details button, type in your preferred rule name and Create. The same process is undergone to create a rule that will trigger the stop Lambda function. The only thing that changes is the Lambda function you are targeting. Follow these steps properly to automatically turns on and off EC2 instances with Lambda and CloudWatch on Amazon Web Services (AWS).

Blogs

How to integrate Python with Tableau

It is no news that Tableau, as a business intelligence software, has made data visualization completely easy for both programmers and non-programmers. Python, on the other hand, is a programming language widely used in the world of data and it is most popular for its strengths in predictive analysis and machine learning. If somehow, we could possibly merge these two data analysis power tools together, integrate python with tableau; wouldn’t that result in a dream data science team for every organization?   In this article, I am going to walk you through how to leverage Python to enhance Tableau’s capabilities and use Tableau to visualize model outputs from Python. This integration completely eradicates the back and forth process of using Tableau to visualize data, going back to Python to structure the model, and bringing it back to Tableau again. All of these can be done in one place using the Tableau + Python server, also known as the Tabpy server. So, sit tight, and let’s get right to it.  To integrate Python with Tableau Desktop, there are, of course, a few steps that must be followed:  Step 1: Install TabPy   Download and install Anaconda. To do this, go to www.anaconda.com/distribution. Downloading Anaconda automatically installs Python and Pip for you. This will save you from the stress of trying to configure parameters for Tabpy.  Open the anaconda prompt, type pip install tabpy-server, hit the “enter” button on your keyboard to install the TabPy server. This may take 3 to 4 minutes.  Still, on the anaconda prompt, type pip install tabpy–client, hit the “enter” button on your keyboard to install the TabPy client. This may take 1 to 2 minutes.  Next, type pip install tabpy to install TabPy. This step is mostly omitted but it is quite necessary, to avoid bugs later into the integration. This may take about a minute. Finally, type tabpy on the anaconda prompt and “enter”. TabPy starts and listens on port 9004. Step 2: Integrate TabPy with Tableau Desktop  Now that we have the TabPy server up and running, the next thing to do is to integrate it with Tableau Desktop. To do this, follow these steps:  Launch Tableau Desktop.  Select “Help” in the top menu bar to display a dropdown menu.  Click “Settings and Performance” in the dropdown menu displayed.  Select the “Manage External Services Connections” option to display a popup.  In the popup displayed, fill in the following details:             Host Name: Local Host          Port: 9004  Select the Test Connection button to integrate TabPy with Tableau Desktop.  Once connection is successful, it only means that you have successfully integrated Python with Tableau using the TabPy server.  If you find this walkthrough helpful, please share. You can also leave a comment in the comments section if you have any question(s). 

Blogs

How to integrate R with Tableau

There are many languages used in the world of data analysis and R, as you probably just guessed, is one of them. According to Wikipedia, R is a language mostly used by statisticians and data miners to build statistical software and data analysis. Integrating R with Tableau will help you take advantage of R functions, packages and even models. Read on to find out how to integrate R with Tableau. Before integrating R with Tableau, it is important that you have both R and RStudio installed on your computer. To download and install R, visit www.cran.r-project.org/bin/windows/base/. For R studio, you can click here. It is important that you have both installed, because their individual functionalities depend on each other. Now, that you have both tools installed, let us proceed to set up Rserve. In case you have been wondering, “how EXACTLY am I going to integrate R with Tableau?” Rserve is the missing link, so let’s get right to it. Step 1: Launch your RStudio. Step 2: Type in “Install.packages(“Rserve”)” and hit the enter button on your keyboard. This process will install Rserve Step 3: Type “library(Rserve)” and hit the enter button to call the Rserve packages Step 4: Finally, type “Rserve()” to start R-Server. From the image below, you can see a walkthrough of all the steps I just listed. The next phase of integrating R with Tableau is going to be carried out on your Tableau Desktop. Open up your Tableau desktop, select Help in the top menu bar to display a dropdown menu. Click on Setting and performance, and select the “Manage external services” option as shown below: Fill in the same credentials (Server: Localhost, Port: 6311) as shown below and click Test connection.  Once the connection is successful, then it means that you have completely integrated R with Tableau

Blogs

Programming: How can I like it?

When you say “I hate programming”, you are most likely echoing the voice of many others that feel the same way you do about programming. In this blog post, I am going to tell you 3 ways you can spark your interest and start liking programming. Computer programming  is the process of designing and building an executable computer program for accomplishing a specific computing result. Programming involves tasks such as; analysis, generating algorithms, profiling algorithms’ accuracy and resource consumption. It is also the implementation of algorithms in a chosen programming language (commonly referred to as coding).  There are so many broad concepts in programming that can make the learning process frustrating and build a sense of hatred in our minds. Personally,  coding assisted me in developing several characteristics such as critical thinking, which is quite important to any successful person. The challenges and tasks in coding steadily increased my knowledge and brought fulfillment and excitement into my work life. I know how “boring” coding might seem to some people, some even think or feel they can never understand the dots and points of programming. For you to be reading this article right now means you want to change that feeling. So here are my 3 tips on how I overcame the “not good enough” feeling. Note: This is not a life hack, but tips to overcome your hatred for programming Identify why you hate programming The reason why most people hate coding is that they can’t seem to figure it out. This automatically makes them feel like they hate it. So, ask yourself if you actually hate it, or if you hate the idea of not being able to figure it out. Once you have identified the problem, you are well on your way to solving it and improving your interest in coding. Work on your mindset The hate you have towards coding came from your mind. The moment I realized this, I immediately started working on my psych towards coding. Just like my attitude toward vegetables, I decided to focus on the benefits of becoming a good programmer. This method created a logic in my head that kept m interested in coding Be open to continuous learning Read code written by people because the first law of programming is  “code is read more than written.” There are multiple resources all over the internet that I used to learn, with quality content for little or no cost. In programming, learning never stops. The more you learn, the more there is to know. Fully exploit these resources, and start with easier coding challenges as you steadily grow.  Program Yes, that’s right. The best way to enjoy coding is to actually code. As you explore several learning resources, look out for challenges. Try these challenges out yourself, till you get them. Trust me, there is a satisfying feeling when you see your codes actually run. These tips really helped me, improved my interest in coding and made me a better programmer. You can adopt them too. Leave comments below on how you think these tips would help and good luck.

Blogs

How to switch to a career in data analysis

Transitioning or switching to a career in data analysis is not a piece of cake, especially if your current career path is non-technical. It is a road paved with many obstacles and you can get overwhelmed and frustrated somewhere along the line. In this blog post, I’m going to discuss a few things that will help you to switch easily to a career in data analysis. I remember when I wanted to switch careers too. I had a long list of courses to take on several learning platforms. In the end, I became overwhelmed and had to retrace many steps back to do it the right way. So, it is completely okay that you are looking online for help on how to switch to a career in data analysis. Note: This is not a life hack. They are just tips that will go a long way in easing your career transition. Step 1: Is transitioning necessary? As much as the world is now data-inclined, a career in data analysis is really not for everybody. Before transitioning, be sure to ask yourself if this switch is necessary. Do you really want to do it? If you are only transitioning because everyone is doing it, then you might not be able to push through when the challenges come. Step 2: Research your position of interest. There are many job positions in data analysis with different sets of required skills. While the title of a data analyst is the most popular one, and most likely the first one you thought of, there are other options. You can be a database administrator, a BI analyst, an IT systems analyst, a healthcare analyst, an operations analyst, etc. Each of these job positions has their required skill sets. Think about the job position you are interested in, and find out the necessary skill sets. Research industries that will require such services and be sure to check how rewarding it is. Step 3: Develop your skills. There are certain skills that are required of almost every data analyst. These skill sets are important when switching to a career in data analysis, and they include: Creative and Analytical thinking: It is critically important to be able to think through problems with a curious and creative point of view. I mean, how can you properly analyze data without good analytical skills? Data visualization: This is an extremely important skill for every data analyst. There are tools specifically built for data visualization, and the best way to fully equip yourself with this skill is to master these tools. A good example is Tableau. Being an expert in Tableau takes your skill level as a data analyst from 0 to 100 real quick. It also increases your chances of getting a job fast. There are many Tableau training programs but I will recommend Cndro’s Tableau training because it focuses on practicality and prepare you for actual on-the-job challenges. Programming languages: One of the most essential skills to effectively switch to a career in data analysis is the ability to read and write in code. Today’s most in-demand analytical languages are R and Python Advanced Microsoft Excel: SQL Databases: SQL databases are relational databases with structured data. Data is stored in tables and a data analyst pulls information from different tables to perform analysis. The ability to do this effectively will further ease your transitioning Data Cleaning: When data isn’t neatly stored in a database, data analysts must use other tools to gather unstructured data. Once they have enough data, they clean using programming. There are many other skills, but their requirement levels can vary depending on the job position. Step 4: Create a Portfolio While switching to a career in data analysis, it is important to create a portfolio. Employers want to see concrete evidence of the things you can do, so start building a portfolio the moment you begin your learning process. As you develop your skills, update your portfolio. Not sure where to start? You can create a GitHub account, or sign up on Kaggle to have access to many open projects that you can practicalize with. These projects will strengthen your portfolio. Step 5: Build a network. It doesn’t matter if you love it or hate it, networking is important if you want to take that giant leap and switch to a career in data analysis. There are different ways to expand your network without going to networking events. You can start by getting the word out about your interest in data analysis to family, friends, and anyone who cares to listen. Post about it on LinkedIn, and connect with people in your field of interest (professionals and amateurs). You can find like-minded people on platforms like Quora and reach out to them for connections, advice, etc. Building and expanding your network will completely ease your transition process to a career in data analysis. Transitioning to data analysis There is no magical process to this, transitioning careers don’t happen overnight, especially to data analysis. You have to be willing to put in the work and develop yourself. If you have started your transitioning process or you are just about to, you can ask questions in the comments section for more help.

Blogs

Tableau Server Client (TSC)

There are different methods used in communicating with the Tableau Server, but one of the outstanding methods is through the Tableau Server Client (TSC). The tableau server is one of the tools in the tableau software product suite. You can read about tableau and it’s tools here. In this article, I am going to share with you what TSC is and how important it is to any Tableau developer What is TSC? Tableau Server Client (TSC) is a python library for the Tableau Server REST API. You can do almost everything on the Tableau Server with the REST API. You can create users, create groups, query projects, query sites to retrieve data sources and workbooks, you can do so much more on the Tableau Server just with the Tableau Server Client. One of the strengths of this python library (TSC), is that you can query multiple data sources and workbooks at a time. TSC allows you to communicate with the tableau server using python programming language, giving you more control over the server. Downloading datasources from Tableau server using TSC. Downloading data sources is an inevitable task for every tableau developer. Since this task is a very common one, I am going to show you how to carry it out effectively using TSC. I’m going to do a quick walkthrough of how to download all the datasources that has been published to the Tableau server default site. For this purpose of this article, I’m going to use the Jupyter notebook. You can also use your favorite IDE to carry out this process. This process is the same for all versions of the tableau server, but I used version 10.5.3. So, let’s jump right in: Step 1: Launch Jupyter notebook. Install TSC using the python line below: !pip install tableauserverclient Step 2: Once the library has been installed, authenticate the connection to the TSC so that Tableau server can identify you as a user. tableau_auth = TSC.TableauAuth(‘USERNAME’, ‘PASSWORD’, ‘SITENAME’) In your case, input your username and password in the respective fields, and “default” as the sitename, because we are trying to download datasources from the default site. If it was from a different site, you will input the name of the site instead. Step 3: After the authentication stage, declare your server to establish a connection between TSC and the server. This can be done with this line of code: server = TSC.Server(‘Your Tableau Server Public IP’) Step 4: Get all the datasources in the default site using this line of code: with server.auth.sign_in(tableau_auth):     all_datasources, pagination_item = server.datasources.get() Step 5: Get all the IDs of the datasources so you can use it in referencing the operations that you want to perform on the site. The code for this step is:     datasource_ids = [datasource.id for datasource in all_datasources]  Step 6: Print the total number of datasources in the default site. Then, print the number of the datasources to be downloaded from the server 10.5.3   print(“\nThere are {} datasources on site “.format(len(all_datasources)))    print(“\nThere are {} datasources to be downloaded on site:  “.format(pagination_item.total_available)) Step 7: Loop through the datasources using their ids and download the datasources to your local machine.     for id in datasource_ids:          if file_download.lower().endswith(‘.tdsx’):          file_download = server.datasources.download(id)         print(file_download)   Step 9: Finally, sign out of the server so your information on it is saved. server.auth.sign_out()  Your Jupyter notebook should look like this image below:   How to download datasources from the tableau server default site. Importance of Tableau Server Client to a Tableau Developer As a Tableau developer, having full understanding and control of the Tableau server is of extreme importance. Tableau Server administration is a required skill in the 21st century as a Tableau Developer. TSC helps you to administer your tableau server easily. It makes you able to send instructions to your server from your local computer, publish datasources and workbooks to the server from your local machine.

Blogs

How to import multiple files in Python

Most times in Python, you get to import just one file using pandas by pd.read(filename) or using the default open() and read() function in. But news flash, you can actually do more!! In this article, I am going to show you how to import multiple files into your Python IDE. Please note that the IDE I used for this process is Jupyter notebook. Pandas can be used to read certain file types as specified in jupyter notebook. These file types include: 1. clipboard 2. Csv 3. excel 4. Feather 5. Fwf 6. Gbq 7. Hdf 8. Html 9. Json 10. Msgpack 11. Parquet 12. Sas 13. Sql 14. Sql query 15. Sql table 16. Stata 17. Table To see this list in your jupyter notebook. This is all you have to do. 1. Be sure you have pandas installed Pip install pandas 2. Import pandas into your jupyter notebook Import pandas as pd 3. Try to read your file and check for other file formats that can be read in python Data = pd.read_#fileformat(filename) (#fileformat is just a place holder for the file format) After the underscore(_) press the tab key on your keyboard. Importing multiple files in Python Importing multiple files in python is done with a module called GLOB Glob is a module that helps to import any file format into python notebook. It is used with several wildcards to import specific file types to prevent import unnecessary files not needed in your python notebook. To get glob installed, you have to run a pip command in your command prompt or Anaconda Prompt Pip install glob3 Importing glob into python (Anaconda) Import glob Importing all the file in your current directory Myfiles = [I for in glob.glob(‘*’)] Note: * is a wildcard which denotes all. This takes all the files in that current directory into python. Importing all excel file formats in Python Myfiles = [I for in glob.glob(‘*.xlsx’)] The above code can also be written in the default way as shown below: Myfiles = [] (This is an empty list) Creating the for loop For each_file in glob.glob(‘*.xlsx’): Myfiles.append(each_file) Print(Myfiles) This will give you all the excel files in your current directory. On occasions where there are fields like data1.xlsx, data2.xlsx, data3.xlsx, data21.xlsx, data22.xlsx, e.t.c; we can use a wildcard (?) to pick certain files. Mynewfiles = [] For each_file in glob.glob(‘data?.xlsx’): Mynewfiles.append(each_file) Print(Mynewfiles) The code above will give us files with the name data1.xlsx, data2.xlsx, data3.xlsx without data21.xlsx, data22.xlsx even though it is an excel format (.xlsx) Import files with a range of numbers Mynewfiles2 = [] (This is an empty list) For each_file in glob.glob(‘data[0-9].xlsx’): Mynewfiles2.append(each_file) Print(Mynewfiles2) This will return files with the numerical values in the specified location in the specified range. Placeholders Using placeholders can be fun just to make your codes more readable and understandable. Combining {} and .format helps in achieving this. Importing only csv files csv_files = [] for each_file in glob.glob(‘*.{}’.format(‘csv’)): csv_files.append(each_file) print(csv_files) Most times, it is preferred to have your file format assigned to a variable. Importing an XML file Fileformat = ‘xml’ xml_files = [] for each_file in glob.glob(‘*.{}’.format(fileformat)): xml_files.append(each_file) print(xml_files) You can import any file format into python using the above method python. To read these files, you can use the open and read functions in python as seen below: for each_data in xml_files: print(open(each_data, ‘r’)) print(open(each_data, ‘r’).read()) This would return the contents of the file (the xml file).

Scroll to Top