def get_price_history(stocks): return df_of_colums data_S = get_price_history("DIS") pd.set_option("display.max_rows", None, "display.max_columns", None) ## how come this doesn't drop the columns? data_S.drop(columns=['high', 'low']) print(data_S[:10]) This is what it prints:
open high low close volume datetime 0 145.54 146.0300 144.31 145.65 8268374.0 1.578290e+12 1 145.99 146.8699 145.42 145.70 6972813.0 1.578377e+12 2 145.49 146.1300 144.82 145.40 6986395.0 1.578463e+12 3 146.47 146.6250 144.61 144.83 6668201.0 1.578550e+12 4 145.30 145.5000 144.26 144.62 5154850.0 1.578636e+12 5 144.75 144.7500 143.36 143.88 9926387.0 1.578895e+12 6 143.41 146.7200 142.29 145.20 14846350.0 1.578982e+12 7 145.71 145.7100 143.93 144.32 6818180.0 1.579068e+12 8 145.09 145.4300 144.44 145.12 6948369.0 1.579154e+12 9 145.54 145.6400 144.01 144.33 10355328.0 1.579241e+12 I also had a question about the difference in print statements. The way the grid works is that the bottom rows are the most recent trading data.
def count_gap_ups(data): # data is the get_price_history # data['open'].iloc[-254] this is how to get the last value open_search_value = 251 close_search_value = 250 gap_up_count = 0 range_count =len(data_S) for num in range(252): open_value = data_S.iloc[open_search_value]["open"] close_value = data_S.iloc[close_search_value]["close"] if open_value > close_value: gap_up_count += 1 open_value -= 1 close_search_value -= 1 return gap_up_count print(str(count_gap_ups(data_S))+ " gap up count") print(str(len(data_S))+ " length of data frame") Prints:
252 gap up count 252 length of data frame While the open price of row 2 is less than the close price of row 1.
Then when I change the number in range() like this.
ef count_gap_ups(data): # data is the get_price_history # data['open'].iloc[-254] open_search_value = 251 close_search_value = 250 gap_up_count = 0 range_count =len(data_S) for num in range(260): open_value = data_S.iloc[open_search_value]["open"] close_value = data_S.iloc[close_search_value]["close"] if open_value > close_value: gap_up_count += 1 open_value -= 1 close_search_value -= 1 return gap_up_count print(str(count_gap_ups(data_S))+ " gap up count") print(str(len(data_S))+ " length of data frame") Returns:
260 gap up count 252 length of data frame How come the for loop doesn't throw an error when there are no more rows to look at?
https://stackoverflow.com/questions/65589650/manipulating-data-in-a-dataframe January 06, 2021 at 11:03AM
没有评论:
发表评论