这是我的代码,我只需要处理最后4列“打开,高,低,关闭”。
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('bmh')
data = json.load(open('GBPUSD_D1.json'))
df = pd.DataFrame(data=data, index=data["time"], columns=data)
print(df.head(5))```
output :
``` ver dataId terminal company server ... open high low close volume3682080 3 NaN forexsb.com外汇软件有限公司高级数据1.95805 1.96417 1.95765 1.96332 146179
3683520 3 NaN forexsb.com外汇软件有限公司高级数据1.96330 1.97418 1.96040 1.97295 157568
3684960 3 NaN forexsb.com外汇软件有限公司高级数据1.97301 1.97490 1.94814 1.95169 147924
3686400 3 NaN forexsb.com外汇软件有限公司高级数据1.95165 1.95296 1.93980 1.94258 148462
3687840 3 NaN forexsb.com外汇软件有限公司高级数据1.94251 1.94316 1.92633 1.92900 142467
5行x32列
发布于 2021-01-08 18:16:22
试一试
df = df[["open", "high", "low", "close"]] # only select four columns或
df = df.drop(df.iloc[:, 0:-5], axis=1) # delete all except last 5 columns
df = df.drop(df.iloc[:, -1], axis=1) # delete last columninplace=True可以在drop调用中使用,以避免复制:
df.drop(df.iloc[:, 0:-5], axis=1, inplace=True)
df.drop(df.iloc[:, -1], axis=1, inplace=True)发布于 2021-01-08 18:16:33
df = df[["open", "high", "low", "close"]]https://stackoverflow.com/questions/65634278
复制相似问题