python DataFrame的用法

编程入门 行业动态 更新时间:2024-10-24 02:29:26

<a href=https://www.elefans.com/category/jswz/34/1770869.html style=python DataFrame的用法"/>

python DataFrame的用法

pandas

首先要import pandas as pd,如果运行时报错找不到pandas则需要下载对应库,下载流程参考以下链接《Phthon下载库函数》

=1001.2014.3001.5502

创建一个DataFrame

import pandas as pdmyList = [['净值日期', "2023-10-26"],['单位净值', 6.66],['累计净值', 9.99],['申购状态', "开放申购"]]
df = pd.DataFrame(data = myList)
print(df)

运行结果:

获取DataFrame的行数和列数

print(df.shape[0]) #行数
print(df.shape[1]) #列数

读取一行数据

获取某一行的数据有两种方式,fundData.loc[[1],:]fundData.loc[1]
fundData.loc[[1],:]显示的时候按照行显示
fundData.loc[1]显示的时候会转置后显示
详情见下图

import akshare as ak
import pandas as pdfundData = ak.fund_etf_fund_info_em(fund="262001",start_date="20231020",end_date="20231024")print(fundData)
print("-------------1------------------")
print(fundData.loc[[1],:])
print("-------------2------------------")
print(fundData.loc[1])

把DataFrame数据导入excel

file_address='D:\\test.xlsx'
df.to_excel(file_address)

更多推荐

python DataFrame的用法

本文发布于:2023-12-03 07:07:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1652488.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:python   DataFrame

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!