Reputation: 108
time open high low close tick_volume spread real_volume
0 2020-01-08 12:00:00 1.11382 1.11385 1.11110 1.11199 9354 1 0
1 2020-01-08 16:00:00 1.11199 1.11308 1.11086 1.11179 10641 1 0
2 2020-01-08 20:00:00 1.11178 1.11178 1.11016 1.11053 4806 1 0
3 2020-01-09 00:00:00 1.11053 1.11193 1.11033 1.11173 3480 1 0
4 2020-01-09 04:00:00 1.11173 1.11189 1.11126 1.11182 2236 1 0
5 2020-01-09 08:00:00 1.11181 1.11203 1.10983 1.10993 7984 1 0
I have this chart and I'm trying to get the values like Open, High, Low and close.
firstvalue = line.split()[4]
i'm getting the error
AttributeError: 'DataFrame' object has no attribute 'split'
please help me how this work.
Upvotes: 1
Views: 41
Reputation: 1930
You have to use the DataFrame.loc
splitting methods to achieve what your want.
Supposing you have a DataFrame called df
:
# You'll get all lines from 'time' column.
df.loc[:,'time']
# Filter index lines from 3 to 5 (both inclusive) and columns from 'time' to 'close'
df.loc[3:5,'time':'close']
# Select the value from 'low' corresponding to index 5
df.loc[5,'low']
# Select the values from columns 'time' and 'low' of corresponding indexes 0, 4 and 5
df.loc[ (0, 4, 5), ('time', 'low') ]
If you want to improve your skills, just check the pandsa.DataFrame.loc
documentation here.
There are a lot of more examples about how to split your DataFrame.
Specific about your error: you are trying to use a string method in a DataFrame object.
That's why you are receiving this error message.
Try to look for DataFrame methods and attributes in this link
Hope this was helpful.
Upvotes: 0
Reputation: 411
This is because you are applying the method 'split'(for strings) on a Pandas DataFrame, but your column is already split. So you should try to do:
print(line['Open'])
In the variable that in this example you call 'line' you have already all the dataset. Maybe because you are reading the file with:
import pandas as pd
line = pd.read_csv('filename.csv') # in this case line contains all the file
print(line['column_name']) # returns the content of an entire column
Upvotes: 2