练习要求:
已知有一个列表中存放了一组音乐数据:
music_data = [(“the rolling stones”,“Satisfaction”),(“Beatles”,“Let It Be”),(“Guns N’ Roses”,“Don’t Cry”),(“Metallica”,“Nothing Else Matters”)]
请根据这组数据创建一个如下的DataFrame:
singer song_name
1 the rolling stones Satisfaction
2 Beatles Let It Be
3 Guns N' Roses Don't Cry
4 Metallica Nothing Else Matters
参考代码:
"""
Spyder Editor
This is a temporary script file.
"""
import pandas as pd
import numpy as np
music_data = [("the rolling stones","Satisfaction"),("Beatles","Let It Be"),("Guns N' Roses","Don't Cry"),("Metallica","Nothing Else Matters")]
ans = pd.DataFrame(data=np.array(music_data) ,index=range(1,5) ,columns=['singer','songname'])
print(ans)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)