Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
6 views

How to load data in pandas dataframe

The document provides a comprehensive table outlining various methods to load data into a pandas DataFrame from different sources, including CSV, JSON, Excel, REST APIs, web scraping, Google Sheets, AWS S3, Google Drive, HTML tables, ZIP files, and various file formats like Pickle, PDF, Word, image, audio, and video. Each method is accompanied by a Python code example for clarity. This guide serves as a useful reference for data loading techniques in Python.

Uploaded by

vm9545331377
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

How to load data in pandas dataframe

The document provides a comprehensive table outlining various methods to load data into a pandas DataFrame from different sources, including CSV, JSON, Excel, REST APIs, web scraping, Google Sheets, AWS S3, Google Drive, HTML tables, ZIP files, and various file formats like Pickle, PDF, Word, image, audio, and video. Each method is accompanied by a Python code example for clarity. This guide serves as a useful reference for data loading techniques in Python.

Uploaded by

vm9545331377
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

How to load data in pandas dataframe

Here's a table summarizing all the ways to load data in Python from different sources:

Data
Method Python Code Example
Source
CSV
from pd.read_csv(url) df = pd.read_csv("https://example.com/data.csv")
Web
JSON
from pd.read_json(url) df = pd.read_json("https://example.com/data.json")
Web
Excel
from pd.read_excel(url) df = pd.read_excel("https://example.com/data.xlsx")
Web
REST
API response =
requests.get(url).j
(JSON son() requests.get("https://api.example.com/data").json();
Respo df = pd.DataFrame(response)
nse)
Web
Scrapi soup =
ng BeautifulSoup BeautifulSoup(requests.get("https://example.com").te
(Static xt, "html.parser")
Page)
Web
Scrapi
driver = webdriver.Chrome();
ng Selenium driver.get("https://example.com"); html =
(Dyna driver.page_source
mic
Page)
df =
Google pd.read_csv(Google pd.read_csv("https://docs.google.com/spreadsheets/d/
Sheets Sheets URL) YOUR_SHEET_ID/export?format=csv")
AWS
boto3.client("s3"). obj = s3.get_object(Bucket="your-bucket",
S3 get_object() Key="data.csv"); df = pd.read_csv(obj["Body"])
Bucket
Google gdown.download(url, gdown.download("https://drive.google.com/uc?
Drive filename) id=FILE_ID", "data.csv")
HTM
L
df_list = pd.read_html("https://example.com"); df =
Table pd.read_html(url) df_list[0]
from
Web
ZIP zipfile.ZipFile().e with zipfile.ZipFile("data.zip", "r") as zip_ref:
xtractall() zip_ref.extractall("folder")
File
Data
Method Python Code Example
Source
(Down
load &
Extrac
t)
Pickle
File
with open("data.pkl", "rb") as file: data =
(Serial pickle.load() pickle.load(file)
ized
Data)
PDF
File
reader = PyPDF2.PdfReader("document.pdf"); text = "\
(Extra PyPDF2.PdfReader() n".join([p.extract_text() for p in reader.pages])
ct
Text)
Word
Docu docx.Document() doc = Document("document.docx"); text = "\
ment n".join([p.text for p in doc.paragraphs])
(.docx)
Image
File
(JPG, cv2.imread() / img = cv2.imread("image.jpg") / img =
PIL.Image.open() Image.open("image.jpg")
PNG,
etc.)
Audio
File librosa.load() audio, sr = librosa.load("audio.wav")
(MP3,
WAV)
Video
File cv2.VideoCapture() cap = cv2.VideoCapture("video.mp4")
(MP4,
AVI)

This table covers structured, unstructured, and multimedia data from web sources, APIs,
cloud storage, and more. 🚀

You might also like