下面的代码与我以前使用的 csv 一起使用,两个 csv 的列数相同,并且列的名称相同。
在这里工作的 csv 的数据
此处没有的 csv 数据
这个错误是什么意思?为什么我收到这个错误?
from pandas import read_csv
from pandas import DataFrame
from pandas import Grouper
from matplotlib import pyplot
series = read_csv('carringtonairtemp.csv', header=0, index_col=0, parse_dates=True, squeeze=True)
groups = series.groupby(Grouper(freq='A'))
years = DataFrame()
for name, group in groups:
years[name.year] = group.values
years = years.T
pyplot.matshow(years, interpolation=None, aspect='auto')
pyplot.show()
Run Code Online (Sandbox Code Playgroud)
from pandas import read_csv
from pandas import DataFrame
from pandas import Grouper
from matplotlib import pyplot
series = read_csv('carringtonairtemp.csv', header=0, …Run Code Online (Sandbox Code Playgroud) 您好,感谢您的帮助!(下面提供的代码和数据)(下图的图像)
我正在尝试向此热图添加一个图例,以解释地图上颜色的差异(较暖的颜色意味着较高的温度)。我添加:
ax1.legend([ax1], ['Temp'])
Run Code Online (Sandbox Code Playgroud)
问题是这行代码不会导致我的绘图包含图例。我需要做什么才能添加解释温度和颜色之间关系的图例?
raw_data = pd.read_csv('https://raw.githubusercontent.com/the-
datadudes/deepSoilTemperature/master/allStationsDailyAirTemp1.csv', index_col=1, parse_dates=True)
df_all_stations = raw_data.copy()
# load the data into a DataFrame, not a Series
# parse the dates, and set them as the index
df1 = df_all_stations[df_all_stations['Station'] == 'Williston']
# groupby year and aggregate Temp into a list
dfg1 = df1.groupby(df1.index.year).agg({'Temp': list})
# create a wide format dataframe with all the temp data expanded
df1_wide = pd.DataFrame(dfg1.Temp.tolist(), index=dfg1.index)
# adding the data between 1990/01/01 -/04/23 and delete the 29th of …Run Code Online (Sandbox Code Playgroud) 预先感谢您的帮助!
我正在尝试在 matplotlib 中创建箱线图,但在尝试添加标签时出现错误。这是引发错误的代码:
df_selected_station_D.boxplot(column='20 cm', by='Month',figsize=(15,5),grid=True, xlabel = 'x data');
Run Code Online (Sandbox Code Playgroud)
这是它导致的错误:
TypeError: boxplot() got an unexpected keyword argument 'xlabel'
Run Code Online (Sandbox Code Playgroud)
这个错误是什么意思以及为什么我会收到它?(完整代码和图片如下)
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')
raw_data = pd.read_csv('all-deep-soil-temperatures.csv', index_col=1, parse_dates=True)
df_all_stations = raw_data.copy()
df_selected_station = df_all_stations[df_all_stations['Station'] == 'Minot']
df_selected_station.fillna(method = 'ffill', inplace=True);
df_selected_station_D=df_selected_station.resample(rule='D').mean()
df_selected_station_D['Day'] = df_selected_station_D.index.dayofyear
mean=df_selected_station_D.groupby(by='Day').mean()
mean['Day']=mean.index
df_selected_station_D['Month'] = df_selected_station_D.index.month
df_selected_station_D.head()
Run Code Online (Sandbox Code Playgroud)
df_selected_station_D.boxplot(column='20 cm', by='Month',figsize=(15,5),grid=True);
Run Code Online (Sandbox Code Playgroud)
您好,提前感谢您的帮助!
当我尝试执行从 GitHub 提取的时间序列分解时,出现ValueError: You Mustspecify a period or x must be a pandas object with a DatetimeIndex with a freq not set to None 。我想我对该错误有了基本的了解,但是当我直接从我的计算机上的文件中提取数据而不是从 GitHub 中提取数据时,我没有收到此错误。为什么只有当我从 GitHub 提取数据时才会出现此错误?我应该如何更改我的代码才能不再出现此错误?
import pandas as pd
import numpy as np
%matplotlib inline
from statsmodels.tsa.seasonal import seasonal_decompose
topsoil = pd.read_csv('https://raw.githubusercontent.com/the-
datadudes/deepSoilTemperature/master/meanDickinson.csv',parse_dates=True)
topsoil = topsoil.dropna()
topsoil.head()
topsoil.plot();
result = seasonal_decompose(topsoil['Topsoil'],model='ad')
from pylab import rcParams
rcParams['figure.figsize'] = 12,5
result.plot();
Run Code Online (Sandbox Code Playgroud) matplotlib ×4
pandas ×4
python ×4
time-series ×3
numpy ×2
arrays ×1
dataframe ×1
statsmodels ×1