Posts

Showing posts from August, 2020

Golden Crossover with MA strategy

Most of the fundamental investors believe in Buy and Hold strategy, but I think most of the retail fundament investors doesn't know when to exit. Also in most cases they get trapped when there is a sudden deterioration in the fundaments. So, for such investors, I believe below is a very good strategy and may save from huge draw-down. This strategy is purely for long term or positional investors. It is combination of two different strategies which are famous among swing or positional traders namely golden crossover (50/200) and 200 moving average. Strategy:  Open stock on a daily time frame chart, draw moving average indicators for 50 and 200 on the chart, these MA indicators will draw 50 days and 200 days moving average of stock. Now for buying the stock you need to see below two conditions: Stock should trade above 200 moving average line. Shorter moving average line should be above longer duration moving average, that means 50 ma line should be above 200 ma line. Similarly f...

Read and print column names of Pandas dataframe

In your development and dealing with huge datasets you may need to read column names of data. Python has very powerful library called as pandas for data processing, pandas have very popular data structure named as Dataframe. There are many ways to get column names of dataframe in pandas library we below: import pandas as pd df = pd.DataFrame({'column1': [2, 4, 8, 0], 'column2': [6, 0, 0, 0], 'column3': [10, 2, 1, 8], 'column4': [14, 5, 32, 68]}) # print Dataframe print(df) # Column names as list print(list(df.columns)) # Column names print(df.columns.values) # iterating the columns for column in df.columns: print(column, end=' ') # using end argument to print all column values in single line. print() # Using toList() function print(df.columns.values.tolist()) Happy coding.

Read and Store data from csv file in Python

In your python development, there are many instances when you need to read some data from CSV or may need to store results (final or intermediate) to csv files, So in this article we will see some ways to read and store Pandas dataframe in csv files.   import pandas as pd df = pd.DataFrame({'column1': [2, 4, 8, 0], 'column2': [6, 0, 0, 0], 'column3': [10, 2, 1, 8], 'column4': [14, 5, 32, 68]}) df.to_csv("temp.csv", index=False) print(pd.read_csv("temp.csv")) # print Dataframe print(df) if you want to raed csv line by line then use csv package as below: import csv with open('temp.csv') as csv_file: csv_reader = csv.reader(csv_file, delimiter=',') line_count = 0 for row in csv_reader: if line_count == 0: print(f'Column names are {", ".join(row)}') line_count += 1 else: pri...