Read-Json-Csv

Sat 17 May 2025

title: "Read JSON Online" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false


import urllib.request, json 
with urllib.request.urlopen("https://gitlab.com/rajacsp/datasets/raw/master/trump.json") as url:
    data = json.loads(url.read().decode())
    print(data['tweets'][0])
{'source': 'Twitter for iPhone', 'id_str': '947824196909961216 …

Category: basics

Read More

Read-Online-Csv

Sat 17 May 2025

title: "Read Online CSV" author: "Raja CSP Raman" date: 2019-04-20 description: "-" type: technical_note draft: false


from io import BytesIO
import requests
import pandas as pd
filename = 'https://gitlab.com/rajacsp/datasets/raw/master/amazon_co_ecommerce_sample.csv'

r = requests.get(filename)
data = r.content
df = pd.read_csv(BytesIO(data), index_col=0)
df …

Category: basics

Read More

Read-Online-Csv-Zip

Sat 17 May 2025

title: "Read Online CSV ZIP" author: "Raja CSP Raman" date: 2019-04-20 description: "-" type: technical_note draft: false


'''
https://stackoverflow.com/questions/37604589/how-can-i-download-a-zipped-file-from-the-internet-using-pandas-0-17-1-and-pytho
'''
from StringIO import StringIO
from zipfile import ZipFile
from urllib import urlopen
import pandas as pd
url = urlopen("https://gitlab.com/rajacsp/datasets/blob/db56e06d7fefed7106d0f527808a50b545b79ef7/archive/amazon_co_ecommerce_sample.csv …

Category: basics

Read More

Read-Sample-Csv-Online

Sat 17 May 2025

title: "Read Sample CSV Online" author: "Raja CSP Raman" date: 2019-04-20 description: "-" type: technical_note draft: false


'''
https://stackoverflow.com/questions/22216076/unicodedecodeerror-utf8-codec-cant-decode-byte-0xa5-in-position-0-invalid-s
'''
'\nhttps://stackoverflow.com/questions/22216076/unicodedecodeerror-utf8-codec-cant-decode-byte-0xa5-in-position-0-invalid-s\n'
from io import BytesIO
import requests
import pandas as pd
filename = 'https://www.sample-videos.com/csv/Sample-Spreadsheet-10-rows.csv'

r = requests.get …

Category: basics

Read More

Read-Text-File-Online

Sat 17 May 2025

title: "Read Text File Online" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false


import urllib.request, json 
data = None
with urllib.request.urlopen("https://gitlab.com/rajacsp/datasets/raw/master/gandhi.txt") as url:
    data = url.read().decode()
data
'Mahatma Gandhi has been variously described as an …

Category: basics

Read More

Read-With-Unicode-Escape

Sat 17 May 2025

title: "Read Online CSV with Unicode Escape" author: "Raja CSP Raman" date: 2019-04-20 description: "-" type: technical_note draft: false


'''
https://stackoverflow.com/questions/22216076/unicodedecodeerror-utf8-codec-cant-decode-byte-0xa5-in-position-0-invalid-s
'''
'\nhttps://stackoverflow.com/questions/22216076/unicodedecodeerror-utf8-codec-cant-decode-byte-0xa5-in-position-0-invalid-s\n'
from io import BytesIO
import requests
import pandas as pd
filename = 'https://www.sample-videos.com/csv/Sample-Spreadsheet-10-rows.csv'

r …

Category: basics

Read More

Reduce

Sat 17 May 2025

title: "Reduce" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false


from functools import reduce
def add(a, b): 
    return a + b
add(10, 15)
25
reduce(add, [10, 20, 30, 40])
100


Score: 5

Category: basics

Read More

Reduce-Advanced

Sat 17 May 2025

title: "Reduce Advanced" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false


from functools import reduce
def do_magic(a, b): 

    if((a % 2 == 1) & (b % 2 == 1) ):
        return a * b

    return a + b
do_magic(10, 15)
25
do_magic(11, 15)
165
reduce(do_magic, [10, 20, 30, 40])
100 …

Category: basics

Read More

Reducer

Sat 17 May 2025

title: "Reducers" author: "Rj" date: 2019-04-20 description: "-" type: technical_note draft: false


import functools as fnt
list = [10, 40, 20, 50, 30, 90]
list
[10, 40, 20, 50, 30, 90]
sum_list = fnt.reduce(lambda x, y: x+y, list)
sum_list
240
def get_sum(list):
    return fnt.reduce(lambda x,y : x …

Category: basics

Read More

Remove Item On Loop

Sat 17 May 2025

title: "Remove Item on Loop" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false


list = [
    1, 2, 3, 4, 5, 6
]
# remove even entries while looping
for i, j in enumerate(list):
    print(i, j)
0 1
1 2
2 3
3 4
4 5
5 6
for …

Category: basics

Read More
Page 12 of 17

« Prev Next »