简体   繁体   English

需要帮助进行股票数据集分析

[英]Need help doing analysis on a stock data set

I created a data frame of stock information such as the "open","high", "close", etc. I now need to calculate the performance for each bar of the stock ( each row in the dataFrame). 我创建了一个股票信息的数据框,例如“开盘价”,“高位”,“收盘价”等。现在,我需要计算股票的每个柱形(dataFrame中的每一行)的性能。 I would like to make a new column in the dataFrame that is equal to the "Close" column of the next row - the "Close" column value of the previous row. 我想在dataFrame中创建一个新列,该列等于下一行的“ Close”列-上一行的“ Close”列值。

  • performance for individual bar is Close of the next bar minus Close of the current bar 单个柱的性能为下一柱的收盘价减去当前柱的收盘价

I tried splitting up the close columns values by every 2nd row and making this new close columns values into its own column. 我尝试按每个第二行拆分close列值,并将此新的close列值制成自己的列。 Then make a new column subtracting this second column with the first one, however they was an issue dealing with the NaN values. 然后创建一个新列,用第一列减去第二列,但是这是处理NaN值的问题。

df['performance'] = df.Close[2] - df.Close[1]

This made the performance for each of the 52767 rows equal to "2.5". 这使52767行中的每一行的性能均等于“ 2.5”。

I would like to make a column 'performance' that does it iteratively. 我想做一列“性能”来进行迭代。 For example if row 0's close value is 5 and row 1's close value is 7, then row 0's performance value should be 2, and this is done for 52767 rows. 例如,如果行0的结束值为5,行1的结束值为7,则行0的性能值应为2,并且对52767行执行此操作。

pandas.Series.diff()

You can use .diff() with a period of -1 to calculate a difference from the subsequent row (as opposed to the normal behavior of difference from the previous row). 可以使用周期为-1 .diff()来计算与下一行的差异(与上一行的差异的正常行为相反)。 For example: 例如:

# Example data
df = pd.read_csv("https://vincentarelbundock.github.io/Rdatasets/csv/fpp2/goog200.csv", index_col=0).head(10)

# Calculate difference
df['performance'] = df['value'].diff(-1)

yields 产量

    time       value  performance
1      1  392.830017     0.317932
2      2  392.512085    -4.793823
3      3  397.305908    -0.705414
4      4  398.011322    -2.478882
5      5  400.490204    -7.605530
6      6  408.095734    -8.494751
7      7  416.590485     3.586670
8      8  413.003815    -0.606048
9      9  413.609863     0.536499
10    10  413.073364          NaN

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 matplotlib 用于库存数据分析 plot 不正确 - matplotlib for stock data analysis plot not correct 需要帮助抓取数据框中的相应数据集 - Need help grabbing a corresponding set of data in a data frame 我需要帮助在 python 中进行双重求和 - I need help doing this double summation in python 使用 datetimeindex 时间序列数据源创建 dataframe 用于股票分析 - Create a dataframe for stock analysis using a datetimeindex timeseries data source 如何在 Python 中转换股票市场 HTML 页面以进行数据分析? - Howt to convert a stock market HTML page for data analysis in Python? Scikit学习和数据集分析 - Scikit learn and data set analysis Pyspark:TaskMemoryManager:分配页面失败:错误分析需要帮助 - Pyspark: TaskMemoryManager: Failed to allocate a page: Need help in Error Analysis 熊猫 dataframe 的任务需要帮助(juypternotebook)帮助新问题“只有公司交易量最大的股票” - Need help in task of panda dataframe (juypternotebook) HELP NEW problem “Only the most traded stock of the firm” 需要帮助理解 while 循环及其作用 - Need help understanding while-loops and what it is doing 对大型数据集执行操作 - Doing operations on a large data set
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM