1. pandas dataframe -> json file
df.to_json("filename.json", default_handler=str)
df.to_json("filename.json", oriend='records', default_handler=str)
2. json file -> pandas dataframe
df = pd.read_json('filename.json')
** large file **
import sys
maxparse = sys.maxsize
while True:
try:
df = pd.read_json("filename.json", dtype=object)
break
except OverflowError:
maxparse = int(maxparse/10)
3. json file
with open("filename.json", mode='r', encoding='utf-8') as file:
data = json.load(file)
with open("filename.json", mode='w', encoding='utf-8') as file:
merged = data + temp
file.seek(0)
json.dump(merged, file)
with open("filename.json", mode='r+', encoding='utf-8') as file:
data = json.load(file)
merged = data + temp
file.seek(0)
json.dump(merged, file)
'python3' 카테고리의 다른 글
[pandas] MinMaxScaling sample code (0) | 2021.11.30 |
---|---|
[pandas] dataframe filter (0) | 2021.11.15 |
[pandas] dataframe get row value / 데이터 전처리 (0) | 2020.06.01 |
[반복문] skip 시 pass/continue (0) | 2020.05.13 |
[type] java.math.BigDecimal to integer (0) | 2020.05.12 |