我使用了 Ipython 控制台,它变成了 3 个这样的错误:
KeyError: 'inline'
ValueError: Invalid GUI request 'inline', valid ones are:dict_keys(['pyglet', 'wx', 'gtk3', 'qt5', 'glut', 'none', 'tk', 'gtk', 'qt4', 'osx', 'qt'])
IPython.core.error.UsageError: Invalid GUI request 'inline', valid ones are:dict_keys(['pyglet', 'wx', 'gtk3', 'qt5', 'glut', 'none', 'tk', 'gtk', 'qt4', 'osx', 'qt'])
Run Code Online (Sandbox Code Playgroud)
那么我应该选择这些键之一吗?或者做其他事情来解决问题?
ps 当我输入下面的行时
%matplotlib --list
Run Code Online (Sandbox Code Playgroud)
表明?
Available matplotlib backends: ['gtk3', 'osx', 'qt5', 'notebook', 'inline', 'tk', 'gtk', 'qt4', 'wx', 'nbagg', 'qt']
Run Code Online (Sandbox Code Playgroud)
关键字“inline”在列表中。但是,当我输入
%matplotlib inline
Run Code Online (Sandbox Code Playgroud)
它变成错误。
我有一个数据帧和下面的字典,但我如何用字典替换列?
data
index occupation_code
0 10
1 16
2 12
3 7
4 1
5 3
6 10
7 7
8 1
9 3
10 4
……
dict1 = {0: 'other',1: 'academic/educator',2: 'artist',3: 'clerical/admin',4: 'college/grad student',5: 'customer service',6: 'doctor/health care',7: 'executive/managerial',8: 'farmer',9: 'homemaker',10: 'K-12student',11: 'lawyer',12: 'programmer',13: 'retired',14: 'sales/marketing',15: 'scientist',16: 'self-employed',17: 'technician/engineer',18: 'tradesman/craftsman',19: 'unemployed',20: 'writer'}
Run Code Online (Sandbox Code Playgroud)
我使用"for"句子进行替换,但它很慢,就像那样:
for i in data.index:
data.loc[i,'occupation_detailed'] = dict1[data.loc[i,'occupation_code']]
Run Code Online (Sandbox Code Playgroud)
由于我的数据包含100万行,如果我只运行1000次,则需要几秒钟.半百万行可能需要半天!
那么有没有更好的方法呢?
非常感谢您的建议!
我有一个日期时间系列,我只想在系列中保留“Hour-Miniute-Second”字符串,并删除 Year-Month-Date 字符串。所以我该怎么做?
原系列:
0 2000-12-31 22:12:40
1 2000-12-31 22:35:09
2 2000-12-31 22:32:48
3 2000-12-31 22:04:35
4 2001-01-06 23:38:11
5 2000-12-31 22:37:48
……
Run Code Online (Sandbox Code Playgroud)
目标:
0 22:12:40
1 22:35:09
2 22:32:48
3 22:04:35
4 23:38:11
5 22:37:48
……
Run Code Online (Sandbox Code Playgroud)
以前,原始系列已经使用pandas.to_datetime(). 但我无法使用这种方法来达到我的目标:(
任何建议表示赞赏!