写点什么

Python 训练营笔记 从 0 完成一个数据分析实战 Day11

发布于: 3 小时前

环境信息

Data Science Workshop


天池龙珠计划 Python 训练营

https://tianchi.aliyun.com/specials/promotion/aicamppython


【Python 入门系列】用 Pandas 揭秘美国选民的总统喜好

https://tianchi.aliyun.com/competition/entrance/531837/introduction


所记录的知识点

  1. ndarray -> str


ndarray -> str

ndarray(str 类型元素) -> str


# ndarray -> strprint("np.array(['1','2','3','544','5'])\n",np.array(['1','2','3','544','5']),"\n")print("type(np.array(['1','2','3','544','5']))\n",type(np.array(['1','2','3','544','5'])),"\n")
print("np.array(['1','2','3','544','5']).tolist()\n",np.array(['1','2','3','544','5']).tolist(),"\n")print("type(np.array(['1','2','3','544','5']).tolist())\n",type(np.array(['1','2','3','544','5']).tolist()),"\n")
print("\" \".join(np.array(['1','2','3','544','5']).tolist())\n"," ".join(np.array(['1','2','3','544','5']).tolist()),"\n")print("type(\" \".join(np.array(['1','2','3','544','5']).tolist()))\n",type(" ".join(np.array(['1','2','3','544','5']).tolist())),"\n")
复制代码


np.array(['1','2','3','544','5']) ['1' '2' '3' '544' '5'] 
type(np.array(['1','2','3','544','5'])) <class 'numpy.ndarray'>
np.array(['1','2','3','544','5']).tolist() ['1', '2', '3', '544', '5']
type(np.array(['1','2','3','544','5']).tolist()) <class 'list'>
" ".join(np.array(['1','2','3','544','5']).tolist()) 1 2 3 544 5
type(" ".join(np.array(['1','2','3','544','5']).tolist())) <class 'str'>
复制代码


ndarray(int 类型元素) -> str


# ndarray -> strprint("np.array([1,2,3,544,5])\n",np.array([1,2,3,544,5]),"\n")print("type(np.array([1,2,3,544,5]))\n",type(np.array([1,2,3,544,5])),"\n")
print("np.array([1,2,3,544,5]).tolist()\n",np.array([1,2,3,544,5]).tolist(),"\n")print("type(np.array([1,2,3,544,5]).tolist())\n",type(np.array([1,2,3,544,5]).tolist()),"\n")
print("\" \".join(str(i) for i in np.array([1,2,3,544,5]).tolist())\n"," ".join(str(i) for i in np.array([1,2,3,544,5]).tolist()),"\n")print("type(\" \".join(str(i) for i in np.array([1,2,3,544,5]).tolist()))\n",type(" ".join(str(i) for i in np.array([1,2,3,544,5]).tolist())),"\n")
复制代码


np.array([1,2,3,544,5]) [  1   2   3 544   5] 
type(np.array([1,2,3,544,5])) <class 'numpy.ndarray'>
np.array([1,2,3,544,5]).tolist() [1, 2, 3, 544, 5]
type(np.array([1,2,3,544,5]).tolist()) <class 'list'>
" ".join(str(i) for i in np.array([1,2,3,544,5]).tolist()) 1 2 3 544 5
type(" ".join(str(i) for i in np.array([1,2,3,544,5]).tolist())) <class 'str'>
复制代码



欢迎各位同学一起来交流学习心得!

欢迎关注微信公众号:悟为生心



发布于: 3 小时前阅读数: 6
用户头像

己所不欲,勿施于人。 2021.05.29 加入

一位喜欢生命科学和计算机科学,崇尚开源精神的码农。

评论

发布
暂无评论
Python训练营笔记 从0完成一个数据分析实战 Day11