Pandas Scratchpad – I

Posted Leave a commentPosted in DataScience, Pandas

This blog is scratchpad for day-to-day Pandas commands. pandas is an open-source, BSD-licensed library providing high-performance, easy-to-use data structures and data analysis tools for the Python programming language. 1. Few quick ways to create Pandas DataFrame DataFrame from Dict of List – DataFrame from List of List – DataFrame from List of Dict – DataFrame […]

Merge json files using Pandas

Posted Leave a commentPosted in Coding, Pandas

Quick demo for merging multiple json files using Pandas – import pandas as pd import glob import json file_list = glob.glob(“*.json”) >>> file_list [‘b.json’, ‘c.json’, ‘a.json’] Use enumerate to assign counter to files. allFilesDict = {v:k for v, k in enumerate(file_list, 1)} >>> allFilesDict {1: ‘b.json’, 2: ‘c.json’, 3: ‘a.json’} Append the data into list […]

Pandas – ValueError: If using all scalar values, you must pass an index

Posted Leave a commentPosted in Pandas, Python

Reading json file using Pandas read_json can fail with “ValueError: If using all scalar values, you must pass an index”. Let see with an example – cat a.json { “creator”: “CaptainAmerica”, “last_modifier”: “NickFury”, “title”: “Captain America: The First Avenger”, “view_count”: 12000 } >>> import pandas as pd >>> import glob >>> for f in glob.glob(‘*.json’): […]