也许是一个菜鸟问题,但从下面的数据框中,我无法弄清楚如何解压缩下面的 B 列,然后只显示具有“关闭”价格的行。
看起来好像 B 列数据是一个需要解包然后以某种方式过滤的字典,因此只显示具有“关闭”值的行,可以是整数或字符串
import pandas as pd
df = pd.DataFrame(
{
"A": {
"1. Information": "Daily Prices (open, high, low, close) and Volumes",
"2. Symbol": "tsla",
"3. Last Refreshed": "2020-01-27",
"4. Output Size": "Full size",
"5. Time Zone": "US/Eastern"
},
"B": {
"2019-09-26": {
"1. open": "230.6600",
"2. high": "243.3100",
"3. low": "227.4000",
"4. close": "242.5600",
"5. volume": "12078785"
},
"2019-09-25": {
"1. open": "224.5600",
"2. high": "228.9800",
"3. low": "218.3600",
"4. close": "228.7000",
"5. volume": "9444286"
},
"2019-09-24": {
"1. open": "241.5200",
"2. high": "241.9900",
"3. low": "222.6100",
"4. close": "223.2100",
"5. volume": "12941112"
},
"2019-09-23": {
"1. open": "240.0000",
"2. high": "245.1794",
"3. low": "239.2200",
"4. close": "241.2300",
"5. volume": "4391630"
}
}
}
)
print(df)
以下是我试图从上面的数据中实现的目标:
import pandas as pd
df = pd.DataFrame()
df['A'] = '2019-09-26','2019-09-25','2019-09-24','2019-09-23'
df['B'] = 242.5600,228.7000,223.2100,241.2300
print(df)
梵蒂冈之花
相关分类