python 3.837
时间: 2023-11-04 20:59:04 浏览: 42
Python 3.8是Python编程语言的一个版本。它于2019年10月发布。Python 3.8引入了许多新的特性和改进,包括表达式赋值、支持海象操作符、位置参数和关键字参数的分隔符、让字典保持插入顺序等。此外,Python 3.8还包括对f-strings(格式化字符串)的改进、更好的异常堆栈跟踪、更快的运行速度等。
相关问题
1:3.835_3.837_3.833_3.839_3.835_3.829_3.835_3.833_3.825_3.839_3.833_3.835_3.844_3.836_3.844_3.839_3.829_3.839_3.836_3.836_3.843_3.839_3.849_3.839_3.831_3.836_3.828_3.823_3.845_3.835_3.844_3.84_3.8用python编写代码切出数值
以下是可以用 Python 获取这个字符串中的数值的代码:
```
s = '1:3.835_3.837_3.833_3.839_3.835_3.829_3.835_3.833_3.825_3.839_3.833_3.835_3.844_3.836_3.844_3.839_3.829_3.839_3.836_3.836_3.843_3.839_3.849_3.839_3.831_3.836_3.828_3.823_3.845_3.835_3.844_3.84_3.8'
numbers = s.split(':')[1].split('_')
for num in numbers:
print(float(num))
```
输出为:
```
3.835
3.837
3.833
3.839
3.835
3.829
3.835
3.833
3.825
3.839
3.833
3.835
3.844
3.836
3.844
3.839
3.829
3.839
3.836
3.836
3.843
3.839
3.849
3.839
3.831
3.836
3.828
3.823
3.845
3.835
3.844
3.84
3.8
```
创建一个Python脚本,命名为test1.py,完成以下功能。(1)今有2018年1月1日—15日的猪肉价格和牛肉价格的数据,它们存在于一个Excel表格中,如下表所示。将其读入Python中并用一个数据框变量df保存。日期猪肉价格牛肉价格2018/1/111382018/1/212392018/1/311.541.32018/1/412402018/1/512432018/1/611.2442018/1/713472018/1/812.6432018/1/913.542.32018/1/1013.9422018/1/1113.843.12018/1/1214422018/1/1313.5392018/1/1414.5382018/1/1514.837.5(2)分别绘制1月1日—10日的猪肉价格和牛肉价格走势图。(3)在同一个figure界面中,用一个2×1的子图分别绘制2018年1月前半个月的猪肉价格和牛肉价格走势图。
我可以回答这个问题。以下是Python脚本test1.py的代码,实现了所需功能:
```python
import pandas as pd
import matplotlib.pyplot as plt
# 读取Excel表格数据
df = pd.read_excel('data.xlsx', index_col=0)
# 绘制1月1日—10日的猪肉价格和牛肉价格走势图
df.loc['2018/1/1':'2018/1/10'].plot()
plt.title('Price Trend from Jan. 1st to Jan. 10th')
plt.xlabel('Date')
plt.ylabel('Price')
plt.show()
# 绘制2018年1月前半个月的猪肉价格和牛肉价格走势图
fig, axs = plt.subplots(2, 1, figsize=(8, 6))
df.loc['2018/1/1':'2018/1/15', '猪肉价格'].plot(ax=axs[0])
axs[0].set_title('Pork Price Trend in Jan.')
axs[0].set_xlabel('Date')
axs[0].set_ylabel('Price')
df.loc['2018/1/1':'2018/1/15', '牛肉价格'].plot(ax=axs[1])
axs[1].set_title('Beef Price Trend in Jan.')
axs[1].set_xlabel('Date')
axs[1].set_ylabel('Price')
plt.tight_layout()
plt.show()
```
注意:这里的Excel表格数据需要事先准备好,并保存为data.xlsx文件。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)