Skip to content

Instantly share code, notes, and snippets.

@wesleyit
Created September 23, 2022 21:37
Show Gist options
  • Save wesleyit/2ff42a06c83c724dc8fededfa7e2131d to your computer and use it in GitHub Desktop.
Save wesleyit/2ff42a06c83c724dc8fededfa7e2131d to your computer and use it in GitHub Desktop.
Import multiple CSV files to the same Pandas dataframe
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "42739c93-36bf-4cab-8caa-90c08a3dd10d",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"import plotly.express as px"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "abe6d02c-e69d-44cf-8b57-4be0c907d914",
"metadata": {},
"outputs": [],
"source": [
"pd.options.plotting.backend = 'plotly'"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "d27578e5-e078-4a4c-b8bf-6f67bf06e586",
"metadata": {},
"outputs": [],
"source": [
"csv_files = [\n",
" '09_2022.csv',\n",
" '10_2022.csv',\n",
" '11_2022.csv',\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "3edf16f8-6c59-497c-9430-eea716be8ab9",
"metadata": {},
"outputs": [],
"source": [
"df = pd.concat(map(pd.read_csv, csv_files))\n",
"df = df.dropna()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "8cd3e6af-e2b6-42a8-b3b0-285e41ab42da",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Customer</th>\n",
" <th>Environment</th>\n",
" <th>ISC Domain Title</th>\n",
" <th>ISC Control ID</th>\n",
" <th>ISC Control</th>\n",
" <th>Rate</th>\n",
" <th>ISC Specification</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Client A</td>\n",
" <td>PRD</td>\n",
" <td>Application</td>\n",
" <td>AP.01</td>\n",
" <td>Adaptive Access Control</td>\n",
" <td>0.0</td>\n",
" <td>Access granted based on combination of factore...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Client A</td>\n",
" <td>PRD</td>\n",
" <td>Application</td>\n",
" <td>AP.02</td>\n",
" <td>DevSecOps</td>\n",
" <td>25.0</td>\n",
" <td>Understand if the most important pieces of a D...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Client A</td>\n",
" <td>PRD</td>\n",
" <td>Application</td>\n",
" <td>AP.03</td>\n",
" <td>Encryption Process</td>\n",
" <td>50.0</td>\n",
" <td>Encryption at rest, at transit, at process, at...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Client A</td>\n",
" <td>PRD</td>\n",
" <td>Application</td>\n",
" <td>AP.04</td>\n",
" <td>Key &amp; Certificate Management</td>\n",
" <td>75.0</td>\n",
" <td>Understand how the sensitive data are handled ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Client A</td>\n",
" <td>PRD</td>\n",
" <td>Application</td>\n",
" <td>AP.05</td>\n",
" <td>SDLC - Software Development Life Cycle</td>\n",
" <td>100.0</td>\n",
" <td>Understand if the SDLC practices are in place,...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>80</th>\n",
" <td>Client C</td>\n",
" <td>Sandbox</td>\n",
" <td>Perimeter</td>\n",
" <td>PR.08</td>\n",
" <td>Guardrails &amp; Policies</td>\n",
" <td>50.0</td>\n",
" <td>Enables to enforce organizational standards an...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>81</th>\n",
" <td>Client C</td>\n",
" <td>Sandbox</td>\n",
" <td>Perimeter</td>\n",
" <td>PR.09</td>\n",
" <td>IDS/IPS - Intrusion Detection and Protection</td>\n",
" <td>25.0</td>\n",
" <td>Intrusion systems to detect and protect agains...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>82</th>\n",
" <td>Client C</td>\n",
" <td>Sandbox</td>\n",
" <td>Perimeter</td>\n",
" <td>PR.10</td>\n",
" <td>Key &amp; Certificate Management</td>\n",
" <td>0.0</td>\n",
" <td>Understand how the sensitive data are handled ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>84</th>\n",
" <td>Client C</td>\n",
" <td>Sandbox</td>\n",
" <td>Perimeter</td>\n",
" <td>PR.12</td>\n",
" <td>NGFW- Next-Generation Firewalls</td>\n",
" <td>100.0</td>\n",
" <td>Implement modern firewalls to deal with latest...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>85</th>\n",
" <td>Client C</td>\n",
" <td>Sandbox</td>\n",
" <td>Perimeter</td>\n",
" <td>PR.13</td>\n",
" <td>WAF - Web Application Firewall</td>\n",
" <td>75.0</td>\n",
" <td>WAF - Web Application Firewall, specially focu...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>233 rows × 7 columns</p>\n",
"</div>"
],
"text/plain": [
" Customer Environment ISC Domain Title ISC Control ID \\\n",
"0 Client A PRD Application AP.01 \n",
"1 Client A PRD Application AP.02 \n",
"2 Client A PRD Application AP.03 \n",
"3 Client A PRD Application AP.04 \n",
"4 Client A PRD Application AP.05 \n",
".. ... ... ... ... \n",
"80 Client C Sandbox Perimeter PR.08 \n",
"81 Client C Sandbox Perimeter PR.09 \n",
"82 Client C Sandbox Perimeter PR.10 \n",
"84 Client C Sandbox Perimeter PR.12 \n",
"85 Client C Sandbox Perimeter PR.13 \n",
"\n",
" ISC Control Rate \\\n",
"0 Adaptive Access Control 0.0 \n",
"1 DevSecOps 25.0 \n",
"2 Encryption Process 50.0 \n",
"3 Key & Certificate Management 75.0 \n",
"4 SDLC - Software Development Life Cycle 100.0 \n",
".. ... ... \n",
"80 Guardrails & Policies 50.0 \n",
"81 IDS/IPS - Intrusion Detection and Protection 25.0 \n",
"82 Key & Certificate Management 0.0 \n",
"84 NGFW- Next-Generation Firewalls 100.0 \n",
"85 WAF - Web Application Firewall 75.0 \n",
"\n",
" ISC Specification \n",
"0 Access granted based on combination of factore... \n",
"1 Understand if the most important pieces of a D... \n",
"2 Encryption at rest, at transit, at process, at... \n",
"3 Understand how the sensitive data are handled ... \n",
"4 Understand if the SDLC practices are in place,... \n",
".. ... \n",
"80 Enables to enforce organizational standards an... \n",
"81 Intrusion systems to detect and protect agains... \n",
"82 Understand how the sensitive data are handled ... \n",
"84 Implement modern firewalls to deal with latest... \n",
"85 WAF - Web Application Firewall, specially focu... \n",
"\n",
"[233 rows x 7 columns]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment