Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

python config file json datatypes

import pandas as pd
import json
import numpy as np

# Create a file (csv) for test purposes 
data = '''
3,10,3.5,abc
3,010,3,bcd'''
file = io.StringIO(data)

# Create a file (json) for test purposes
json_data = '''
{
   "header":[
       ["field1","int16"],
       ["field2","float32"],
       ["field3","float64"],
       ["field4","str"]]
}'''

# Load json to dictionary
json_d = json.loads(json_data)

# Fetch field names and dtypes
names = [i[0] for i in json_d['header']]
dtype = dict(json_d['header'])

# Now use pandas to read the whole thing to a dataframe
df = pd.read_csv(file,header=None,names=names,dtype=dtype)

# Output as dict (this can be passed to a json file with json.dump())
df.to_dict('r')
Comment

PREVIOUS NEXT
Code Example
Javascript :: V2271823410017645510 
Javascript :: adonis select distinct inner join 
Javascript :: mat slider in a reactve form 
Javascript :: identify chrome on android using javascript 
Javascript :: rangeSlider format price js 
Javascript :: json etudients 
Javascript :: p5js add canvas in middle 
Javascript :: jquery.validate.unobtrusive dynamic content 
Javascript :: js fill array with count elements 
Javascript :: difference between Redis and StrictRedis 
Javascript :: curl node exporter 
Javascript :: vue slot events 
Javascript :: passing a variable to the width style div angular 
Javascript :: element ui loading schange text 
Javascript :: cargar datos de un id con inner join vue js 
Javascript :: blazor auto reconnect 
Javascript :: axios mock parameter 
Javascript :: simple editor reacct 
Javascript :: initial min js 
Javascript :: javascript kommentare 
Javascript :: Decodes a string of data which has been encoded using base-64 encoding - Nodejs 
Javascript :: js try catch err.printstacktrace 
Javascript :: selectize get instance id from onchange 
Javascript :: sinon chaining method 
Javascript :: how to speak numbers in javascript 
Javascript :: grotesque meaning 
Javascript :: petrov attack 
Javascript :: vs code { key to to go brace 
Javascript :: i need to add content-type accept form data using node.js in middelware 
Javascript :: app-root modal component 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =