When you save JSON files in a data frame format in Python, you want to create them sorted by the values in a specific column

Asked 2 years ago, Updated 2 years ago, 62 views

Hi, how are you?

I downloaded the company's financial statements in Json format using the Open API of the electronic disclosure system DART. You can find more information about this API in the link below. https://opendart.fss.or.kr/guide/main.do?apiGrpCd=DS003

When I checked the financial statements of the company obtained through the API, it was in the following format. As a result of receiving the financial statements of a specific company in 2018, the first four columns were overlapping values, and account_nm and account_detail seemed to be important for the company's financial statements.

I think we need to sort using these two columns, so can we sort by columns = and then divide account_detail into several columns according to the value?

For example, account_nm is end-term capital and account_detail is capital[member] other capital items so I'd like to divide account_detail_1 into other capital items.

I would appreciate it if you could give me an answer.

json python dataframe api

2022-09-20 22:22

1 Answers

I couldn't catch exactly what you wanted, but I think it would be good to make split based on the string [member] and then handle it after making it into each column.

Examples are as follows:

Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> import pandas as pd


>>> df = pd.DataFrame({ 'detail':[ '1[m]', '2[m]3[m]', '3[m]', '4'] })
>>> df
     detail
0      1[m]
1  2[m]3[m]
2      3[m]
3         4
>>> df.detail.str.split('\[m\]', expand=True)
   0     1     2
0  1        None
1  2     3      
2  3        None
3  4  None  None
>>> df.detail.str.split('\[m\]', expand=True).fillna('')
   0  1 2
0  1     
1  2  3  
2  3     
3  4     
>>> df[['d1', 'd2', 'd3']]=df.detail.str.split('\[m\]', expand=True).fillna('')
>>> df
     detail d1 d2 d3
0      1[m]  1      
1  2[m]3[m]  2  3   
2      3[m]  3      
3         4  4      

Split a string column with a specific token as a delimiter, expand to become a data frame, and assign the result to the original df column name.


2022-09-20 22:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.