[英]how can I make range with text and make this to y-axis in plot
I have two questions! 我有两个问题!
Q1. Q1。 first I want to make a list like
首先,我想列出一个清单
df.CellNo = [Cell1,Cell2,Cell3,...,Cell96]
so I tried df.CellNo = ['CellNo'] + range(1,97)
but it was not working. 所以我尝试了
df.CellNo = ['CellNo'] + range(1,97)
但是它不起作用。
so I did a code like behind. 所以我做了像后面的代码。
df = pd.DataFrame({'CellNo': range(1,97)})
df.CellNo = df.CellNo.astype(str)
df.CellNo = 'Cell' + df.CellNo
Is there any easier way to do this?? 有没有更简单的方法可以做到这一点? (in short way)
(简而言之)
Q2. Q2。 second I want to plot with x-axis is 'Time' data and y-axis is df.CellNo data when I just plot df
第二个我想用x轴绘制的是'时间'数据,而y轴是df。
I want to make y-axis sorted by nuber like Cell5, Cell6, Cell7, Cell10, Cell11 ... from behind.
我想从后面按像Cell5,Cell6,Cell7,Cell10,Cell11 ...这样的nuber对y轴进行排序。 how can I do,,
我能怎么做,,
IIUC, this is about sorting dataframe by substring. IIUC,这是关于按子字符串对数据帧进行排序。
You can make a key column and then sort the dataframe: 您可以创建一个关键列,然后对数据框进行排序:
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({'Time' : [20190721,20190722,20190723], 'No':['A90','A5','A10']})
df['key'] = df['No'].str.extract('(\d+)').astype(int)
df.sort_values('key', inplace=True)
plt.scatter(df.Time,df.No)
Output: 输出:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.