# %%
import pandas as pd
import numpy as np
# %%
df = pd.read_csv('标普500财务数据项目.csv', sep=',')
# %%
df
# %%
atq = df.iloc[:, [0,1,2,4]]
niq = df.iloc[:, [0,1,2,5]]
revtq = df.iloc[:, [0,1,2,6]]
teqq = df.iloc[:, [0,1,2,7]]
# %%
atq
# %%
niq
# %%
revtq
# %%
teqq
# %%
atq = pd.pivot_table(atq, values='atq', index='gvkey', columns=['fyearq', 'fqtr'])
# %%
atq
# %%
niq = pd.pivot_table(niq, values='niq', index='gvkey', columns=['fyearq', 'fqtr'])
revtq = pd.pivot_table(revtq, values='revtq', index='gvkey', columns=['fyearq', 'fqtr'])
teqq = pd.pivot_table(teqq, values='teqq', index='gvkey', columns=['fyearq', 'fqtr'])
# %%
niq
# %%
revtq
# %%
teqq
# %%
atq.to_excel('atq.xlsx',sheet_name = "Sheet1")
# %%
niq.to_excel('niq.xlsx')
revtq.to_excel('revtq.xlsx')
teqq.to_excel('teqq.xlsx')
标签:niq,python,透视,%%,pd,atq,teqq,数据,revtq
From: https://www.cnblogs.com/tiansz/p/16722452.html