0

this is my code and i just need to treat the last 4 columns "open, high, low, close"

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  volume
3682080    3     NaN  forexsb.com  Forex Software Ltd  Premium Data  ...  1.95805  1.96417  1.95765  1.96332  146179
3683520    3     NaN  forexsb.com  Forex Software Ltd  Premium Data  ...  1.96330  1.97418  1.96040  1.97295  157568
3684960    3     NaN  forexsb.com  Forex Software Ltd  Premium Data  ...  1.97301  1.97490  1.94814  1.95169  147924
3686400    3     NaN  forexsb.com  Forex Software Ltd  Premium Data  ...  1.95165  1.95296  1.93980  1.94258  148462
3687840    3     NaN  forexsb.com  Forex Software Ltd  Premium Data  ...  1.94251  1.94316  1.92633  1.92900  142467

[5 rows x 32 columns]```

2 Answers2

0

Try

df = df[["open", "high", "low", "close"]] # only select four columns

or

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 column

inplace=True can be used in the drop calls to avoid copies:

df.drop(df.iloc[:, 0:-5], axis=1, inplace=True)
df.drop(df.iloc[:, -1], axis=1, inplace=True)
nspo
  • 1,488
  • 16
  • 21
0
df = df[["open", "high", "low", "close"]]
double-beep
  • 5,031
  • 17
  • 33
  • 41