Read-Json-Csv
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 …
Read More
Read-Online-Csv
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)
Read More
Read-Online-Csv-Zip
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 …
Read More
Read-Sample-Csv-Online
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 …
Read More
Read-Text-File-Online
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()
'Mahatma Gandhi has been variously described as an …
Read More
Read-With-Unicode-Escape
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 …
Read More
Reduce
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
reduce(add, [10, 20, 30, 40])
Score: 5
Read More
Reduce-Advanced
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
reduce(do_magic, [10, 20, 30, 40])
Read More
Reducer
title: "Reducers"
author: "Rj"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
list = [10, 40, 20, 50, 30, 90]
sum_list = fnt.reduce(lambda x, y: x+y, list)
def get_sum(list):
return fnt.reduce(lambda x,y : x …
Read More
Remove Item On Loop
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)
Read More