首页 > 编程语言 >python数据透视表

python数据透视表

时间:2022-09-23 13:57:15浏览次数:41  
标签:niq python 透视 %% pd atq teqq 数据 revtq

# %%
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

相关文章