pandas 如何删除一个框架的标题的第一行并更改标题名称

ego6inou  于 2023-11-15  发布在  其他
关注(0)|答案(1)|浏览(120)

我得到了一个函数来返回包含Panda DataFrame的数据,如下所示

RSI
Date                                
2023-10-02 00:00:00+11:00        NaN
2023-10-03 00:00:00+11:00        NaN
2023-10-04 00:00:00+11:00        NaN
2023-10-05 00:00:00+11:00        NaN
2023-10-06 00:00:00+11:00        NaN
2023-10-09 00:00:00+11:00        NaN
2023-10-10 00:00:00+11:00        NaN
2023-10-11 00:00:00+11:00        NaN
2023-10-12 00:00:00+11:00        NaN
2023-10-13 00:00:00+11:00        NaN
2023-10-16 00:00:00+11:00        NaN
2023-10-17 00:00:00+11:00        NaN
2023-10-18 00:00:00+11:00        NaN
2023-10-19 00:00:00+11:00        NaN
2023-10-20 00:00:00+11:00  47.058827
2023-10-23 00:00:00+11:00  50.212766
2023-10-24 00:00:00+11:00  47.185484
2023-10-25 00:00:00+11:00  44.308668
2023-10-26 00:00:00+11:00  44.308668
2023-10-27 00:00:00+11:00  44.308668
2023-10-30 00:00:00+11:00  44.308668

字符串
我想删除标题的第一行,并添加标题名称的第二列“RSI”如下。我已经谷歌了很多,试图使用df.iloc[0]等,但没有成功。

Date                             RSI  
2023-10-02 00:00:00+11:00        NaN
2023-10-03 00:00:00+11:00        NaN
2023-10-04 00:00:00+11:00        NaN
2023-10-05 00:00:00+11:00        NaN
2023-10-06 00:00:00+11:00        NaN
2023-10-09 00:00:00+11:00        NaN
2023-10-10 00:00:00+11:00        NaN
2023-10-11 00:00:00+11:00        NaN
2023-10-12 00:00:00+11:00        NaN
2023-10-13 00:00:00+11:00        NaN
2023-10-16 00:00:00+11:00        NaN
2023-10-17 00:00:00+11:00        NaN
2023-10-18 00:00:00+11:00        NaN
2023-10-19 00:00:00+11:00        NaN
2023-10-20 00:00:00+11:00  47.058827
2023-10-23 00:00:00+11:00  50.212766
2023-10-24 00:00:00+11:00  47.185484
2023-10-25 00:00:00+11:00  44.308668
2023-10-26 00:00:00+11:00  44.308668
2023-10-27 00:00:00+11:00  44.308668
2023-10-30 00:00:00+11:00  44.308668


以下是我的代码:

rsiData = getRSI(asx_stock)
print("rsiData type:", type(rsiData))

df = pd.DataFrame(data=rsiData)
print(df)
monthly_rsiData_html = Markup(df.to_html())


任何人都可以帮助我解决这个问题,将不胜感激?提前谢谢你

7cwmlq89

7cwmlq891#

似乎Pandas使用日期作为索引。试试:

df = pd.DataFrame(data=rsiData, columns=['Date', 'RSI'])

字符串
否则,正如@Nick在评论中建议的那样:df.reset_index()

相关问题