如何绘制 python 中一行的聊天记录?
How can I plot line chat of a row in python?
如何在 python 中绘制一行的聊天记录?
我提取了这样一行:
cases_df[cases_df['Country/Region']=='India']
我已经提取了这样一行,想绘制它的折线图以查看 covid 情况下的上升。
cases_df[cases_df['Country/Region']=='India'].plot()
此代码无效
如何绘制这一行的折线图?
我认为最简单的方法是 select 数据列并转置它们:
df_ = cases_df[cases_df['Country/Region']=='India']
#Select all columns after the 4th
df_ = df_.iloc[:, 4:]
#Transpose
df_ = df_.T
#Optional: convert index to dates for a better-looking plot
df_ = df_.set_index(pd.to_datetime(df_.index, format = "%m/%d/y"))
df_.plot()
我想出了这个代码:
#Remove unnecessary columns
a = cases_df.drop(columns=["Province/State", "Lat", "Long"])
#Select India
a[a['Country/Region']=='India']
#Remove catarogical columns completely
b = cases_df.drop(columns=["Province/State", "Country/Region", "Lat", "Long"])
#Plotting India cases numerical columns
plt.figure(figsize=(23,6))
b.iloc[a[a['Country/Region']=='India'].index[0]].plot()
问题是数字列和分类列混合在一起。所以,我先把它们分开了。
如何在 python 中绘制一行的聊天记录?
我提取了这样一行:
cases_df[cases_df['Country/Region']=='India']
我已经提取了这样一行,想绘制它的折线图以查看 covid 情况下的上升。
cases_df[cases_df['Country/Region']=='India'].plot()
此代码无效
如何绘制这一行的折线图?
我认为最简单的方法是 select 数据列并转置它们:
df_ = cases_df[cases_df['Country/Region']=='India']
#Select all columns after the 4th
df_ = df_.iloc[:, 4:]
#Transpose
df_ = df_.T
#Optional: convert index to dates for a better-looking plot
df_ = df_.set_index(pd.to_datetime(df_.index, format = "%m/%d/y"))
df_.plot()
我想出了这个代码:
#Remove unnecessary columns
a = cases_df.drop(columns=["Province/State", "Lat", "Long"])
#Select India
a[a['Country/Region']=='India']
#Remove catarogical columns completely
b = cases_df.drop(columns=["Province/State", "Country/Region", "Lat", "Long"])
#Plotting India cases numerical columns
plt.figure(figsize=(23,6))
b.iloc[a[a['Country/Region']=='India'].index[0]].plot()
问题是数字列和分类列混合在一起。所以,我先把它们分开了。