Harika22 commited on
Commit
63f0d8a
·
verified ·
1 Parent(s): 3894596

Update pages/6_Semi_structured_data.py

Browse files
Files changed (1) hide show
  1. pages/6_Semi_structured_data.py +14 -0
pages/6_Semi_structured_data.py CHANGED
@@ -311,11 +311,25 @@ elif file_type == "JSON":
311
  ''')
312
  st.code('''import pandas as pd
313
  a = '{"name":["harii","sree","gowtham"],"age":[21,24,25],"weight":[34,45,67]}'
 
314
  ind = data.to_json(orient="index")
315
  ind
316
  output = '{"0":{"name":"harii","age":21,"weight":34},"1":{"name":"sree","age":24,"weight":45},"2":{"name":"gowtham","age":25,"weight":67}}'
317
  ''')
318
 
 
 
 
 
 
 
 
 
 
 
 
 
 
319
 
320
 
321
 
 
311
  ''')
312
  st.code('''import pandas as pd
313
  a = '{"name":["harii","sree","gowtham"],"age":[21,24,25],"weight":[34,45,67]}'
314
+ data = pd.read_json(a)
315
  ind = data.to_json(orient="index")
316
  ind
317
  output = '{"0":{"name":"harii","age":21,"weight":34},"1":{"name":"sree","age":24,"weight":45},"2":{"name":"gowtham","age":25,"weight":67}}'
318
  ''')
319
 
320
+ st.subheader("Orient as Columns...")
321
+ st.markdown('''
322
+ - In orient as columns while converting DataFrame into json here keys become column names and values are dictionary
323
+ - Inside dictionary keys are indices and values are values present in the data
324
+ ''')
325
+ st.code('''import pandas as pd
326
+ a = '{"name":["harii","sree","gowtham"],"age":[21,24,25],"weight":[34,45,67]}'
327
+ data = pd.read_json(a)
328
+ col = data.to_json(orient="columns")
329
+ col
330
+ output = '{"name":{"0":"harii","1":"sree","2":"gowtham"},"age":{"0":21,"1":24,"2":25},"weight":{"0":34,"1":45,"2":67}}'
331
+ ''')
332
+
333
 
334
 
335