Python primer for Trading

VJAY

Well-Known Member
#21
Reading files

The most common format is csv. Let's read it. You can download the file here.
Download and put it in the same folder from where you run your jupyter notebook


Python:
import pandas as pd
filename = 'SBIN.csv'
df = pd.read_csv(filename, parse_dates=['Date'])
df
Comments (single line) start with a # in python
I import the pandas library (required for reading files)
You could change the filename to anything. If its somewhere else in your computer, include the entire path
The read_csv function reads the file and parses it into a dataframe for easy analysis. parse_dates indicates that the Date column should be regarded as date


Running the above should give you the following output

View attachment 27226
Dear UB,
Am stuck here ...file not found error comes.....I put sbi csv file in C drive where my other pair trading stockdata file have...Is I need this file to put in anaconda folders its in D drive?

Untitled.png
 

UberMachine

Well-Known Member
#22
Dear UB,
Am stuck here ...file not found error comes.....I put sbi csv file in C drive where my other pair trading stockdata file have...Is I need this file to put in anaconda folders its in D drive?

View attachment 27284
From where did you run jupyter notebook.
Could you attach a screenshot of the cmd from which jupyter is run?
Else you could change filename to 'D:/SBIN.csv' or 'D:\SBIN.csv'
Not sure which one works in Windows :)
 
Last edited:

MSN1979

Well-Known Member
#23
Vijay I faced the same problem and solved it by savinf the csv in C:\Users\Vijay
 

MSN1979

Well-Known Member
#24
Done
 
Last edited:

VJAY

Well-Known Member
#26
From where did you run jupyter notebook.
Could you attach a screenshot of the cmd from which jupyter is run?
Else you could change filename to 'D:/SBIN.csv' or 'D:\SBIN.csv'
Not sure which one works in Windows :)
It solved when file name changed....Thanks
 

VJAY

Well-Known Member
#27
Dear UB,
completed all...I got output file...only thing not worked is calculate 7 MA is it due to not installed talib?also want to know how can put PLAY button infront of every cells?

1533898836020.png
 

UberMachine

Well-Known Member
#28
Dear UB,
completed all...I got output file...only thing not worked is calculate 7 MA is it due to not installed talib?also want to know how can put PLAY button infront of every cells?

View attachment 27341
:up:
Press CTRL+ENTER to run a cell (don't think there is an option for run button in each cell)
Looks you have already calculated MA (moving average doesn't require talib)
Python:
df['Close'].rolling(7).mean()
calculates rolling mean on close price based on a 7 day window = 7MA
 

MSN1979

Well-Known Member
#29
Hi Uber

I would like to learn how to work with data inside a csv file

Few example that would help

take 2 colums and compare data. Lets say I would like to find common stocks in all colums
print stocks that are more then 1 colum or 2 coloums or 3 etc.

PS: Its not allowing me to attach a csv here. How can i send u?
 
Last edited:

VJAY

Well-Known Member
#30
Hi Uber

I would like to learn how to work with data inside a csv file

Few example that would help

take 2 colums and compare data. Lets say I would like to find common stocks in all colums
print stocks that are more then 1 colum or 2 coloums or 3 etc.

PS: Its not allowing me to attach a csv here. How can i send u?
Upload into google drive and share link here....