0
import pandas as pd

df = pd.read_csv("C:/Users/Usuario/Desktop/algotrade/GFG.csv", sep=";", parse_dates=["Date"],dayfirst=True,index_col='Date')

df.head(10)
Out[131]: 
              Open    High     Low   Close  Volume
Date                                              
2018-06-01   107,1   107,9   104,5   106,2  518031
2018-05-31     106     107   103,5   105,8  373753
2018-05-30   103,3     107   103,3   104,6  476260
2018-05-29  103,65  106,45  100,05   102,9  963397
2018-05-28   107,7   108,5     103  103,75  498876
2018-05-24   107,6  111,75   106,7   107,7  477271
2018-05-23   109,9   110,7   108,1   108,4  781355
2018-05-22     115     115   110,3   111,6  697742
2018-05-21     115   115,5     114  114,45  655710
2018-05-18     117     117     114  114,35  941734

df.tail()
Out[132]: 
                   Open         High          Low        Close   Volume
Date                                                                   
2010-01-08  2,104914286  2,104914286  2,056413956  2,075814088  1289394
2010-01-07  2,075814088  2,134014483  2,056413956  2,124314417  2773188
2010-01-06  2,114614351  2,134014483  2,066114022  2,085514154  3233258
2010-01-05  2,114614351  2,201914944  2,114614351  2,172814746  2624534
2010-01-04  2,114614351  2,134014483   2,09521422  2,114614351  1485340

df.index
Out[133]: 
DatetimeIndex(['2018-06-01', '2018-05-31', '2018-05-30', '2018-05-29',
               '2018-05-28', '2018-05-24', '2018-05-23', '2018-05-22',
               '2018-05-21', '2018-05-18',
               ...
               '2010-01-15', '2010-01-14', '2010-01-13', '2010-01-12',
               '2010-01-11', '2010-01-08', '2010-01-07', '2010-01-06',
               '2010-01-05', '2010-01-04'],
              dtype='datetime64[ns]', name='Date', length=2050, freq=None)

df.columns
Out[134]: Index(['Open', 'High', 'Low', 'Close', 'Volume'], dtype='object')

ts = df['Close'][-10:]

print(ts)
Date
2010-01-15    2,056413956
2010-01-14    2,056413956
2010-01-13     1,97881343
2010-01-12    1,910912969
2010-01-11    1,988513496
2010-01-08    2,075814088
2010-01-07    2,124314417
2010-01-06    2,085514154
2010-01-05    2,172814746
2010-01-04    2,114614351
Name: Close, dtype: object

type(ts)
Out[137]: pandas.core.series.Series

**Tengo otra consulta:
Quiero agregar una columna que me muestre una operacion atirmetica (resta)**

df['diff'] = df.Open - df.Close 

me da el siguiente error TypeError: unsupported operand type(s) for -: 'str' and 'str'

Alguien me puede dar luces porfavor?

3

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.