pd.read_html, read_xml, read_json => BeautifulSoup 이용하자!
df = pd.DataFrame({"foo": range(5), "bar": range(5, 10)})
import pandas as pd
df = pd.read_csv('data.csv')
df = pd.read_csv(os.path.join(_DATA_DIR,"_.txt"), delimiter="\t")
df.to_csv(index=False)
# out.csv를 지니는 out.zip 생성
compression_opts = dict(method='zip', archive_name='out.csv')
df.to_csv('out.zip', index=False, compression=compression_opts)
# folder에 csv 파일을 쓰기 위해서 path 지정
# version 1.
from pathlib import Path
filepath = Path('folder/subfolder/out.csv')
filepath.parent.mkdir(parents=True, exist_ok=True)
df.to_csv(filepath)
# version 2.
import os
os.makedirs('folder/subfolder', exist_ok=True)
df.to_csv('folder/subfolder/out.csv')
df = pd.read_table('_.txt')
df = pd.read_table('data.csv')
DataFrame.to_pickle(path, compression='infer', protocol=HIGHEST_PROTOCOL, storage_options=None)
df.to_pickle("./dummy.pkl") # 버전 0.20.3. 이하에서만 보장된다.
df = pd.read_pickle("./dummy.pkl")
df = pd.read_excel('tmp.xlsx', index_col=0)
df = pd.read_excel(open('tmp.xlsx', 'rb'), sheet_name='Sheet3')
df = pd.read_excel('tmp.xlsx', index_col=None, header=None)
df = pd.read_excel('tmp.xlsx', index_col=0, dtype={'Name': str, 'Value': float})
df = pd.read_excel('tmp.xlsx', index_col=0, na_values=['string1', 'string2'])
df = pd.read_excel('tmp.xlsx', index_col=0, comment='#')
df.to_excel("output.xlsx")
df.to_excel("output.xlsx", sheet_name='Sheet_name_1')
# 2 sheet 이상 작성하고 싶을 때
with pd.ExcelWriter('output.xlsx') as writer:
df1.to_excel(writer, sheet_name='Sheet_name_1')
df2.to_excel(writer, sheet_name='Sheet_name_2')
# 기존 있는 excel 파일에 data append
with pd.ExcelWriter('output.xlsx', mode='a') as writer:
df.to_excel(writer, sheet_name='Sheet_name_3')
pd.read_json(path, orient='split')
pd.read_json(path, orient='index')
pd.read_json(path, orient='records')
pd.read_json(path, orient='table')
df.to_json(orient='split')
df.to_json(orient='index')
df.to_json(orient='records')
result = df.to_json(orient='table')
parsed = json.loads(result)
json.dumps(parsed, indent=4)