我最近发布了一个关于在欧洲城市绘制位置作为地图上的点的问题.请参阅R,获取城市的经度/纬度数据并将其添加到我的数据框中
城市xlsx文件包含欧洲约20000个城市.
尝试使用地理编码查找纬度/经度数据时收到错误消息.我已经插入了下面的部分代码:
cities <- read.xlsx("EU_city.xlsx",1)
# get frequencies
freq <- as.data.frame(table(cities))
library(plotrix)
freq$Freq <- rescale(freq$Freq, c(1,10)) # c(scale_min, scale_max)
# get cities latitude/longitude - kindly provided by google:
library(ggmap)
lonlat <- geocode(unique(cities))
cities <- cbind(freq, lonlat)
error message:
Error: is.character(location) is not TRUE
Run Code Online (Sandbox Code Playgroud)
我猜我的数据框中的数据(城市)在地理编码调用中找不到.如果在地理编码中不匹配,有没有办法忽略dtaframe中的城市
建议后更新问题.......
尝试过地理编码(as.character(cities))
然后我的框架看起来像这样:
> cities <- cbind(freq, lonlat)
> cities
cities Freq lon lat
1 ARNHEM 1.00 NA NA
2 ATHENS 3.25 NA NA
3 BAAR 1.00 NA NA
4 BAD VILBEL 1.00 NA …Run Code Online (Sandbox Code Playgroud) 我想使用circlize包制作一个和弦图.我有一个包含四列汽车的数据框.2个第一列包含有关汽车频段和所拥有车型的信息,以及受访者迁移到的品牌和型号的下两列.
这是一个简单的数据框示例:
Brand_from model_from Brand_to Model_to
1: VOLVO s80 BMW 5series
2: BMW 3series BMW 3series
3: VOLVO s60 VOLVO s60
4: VOLVO s60 VOLVO s80
5: BMW 3series AUDI s4
6: AUDI a4 BMW 3series
7: AUDI a5 AUDI a5
Run Code Online (Sandbox Code Playgroud)
将它变成和弦图会很棒.我在帮助中找到了一个有效的例子但是我无法将我的数据转换成正确的格式以制作情节.此代码来自circlize包中的帮助.这产生了一层,我想我需要两个,品牌和型号.
mat = matrix(1:18, 3, 6)
rownames(mat) = paste0("S", 1:3)
colnames(mat) = paste0("E", 1:6)
rn = rownames(mat)
cn = colnames(mat)
factors = c(rn, cn)
factors = factor(factors, levels = factors)
col_sum = apply(mat, 2, sum)
row_sum = apply(mat, 1, …Run Code Online (Sandbox Code Playgroud) 我将Pandas数据帧写入csv文件时遇到问题.我猜有些som字符无法翻译,但我不知道如何解决这个问题.我需要帮助.
这是我的简单调用和错误消息:
big_frame.to_csv('C:\DRO\test.csv')
Run Code Online (Sandbox Code Playgroud)
错误:
C:\Python27\lib\site-packages\pandas\lib.pyd in pandas.lib.write_csv_rows (pandas\lib.c:13528)()
UnicodeEncodeError: 'ascii' codec can't encode character u'\xd6' in position 1: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud) 我想从另一个数据帧中减去一行中的所有行.(与一行的差异)
是否有捷径可寻?(比如df-df2)
df = pd.DataFrame(abs(np.floor(np.random.rand(3, 5)*10)),
... columns=['a', 'b', 'c', 'd', 'e'])
df
Out[18]:
a b c d e
0 8 9 8 6 4
1 3 0 6 4 8
2 2 5 7 5 6
df2 = pd.DataFrame(abs(np.floor(np.random.rand(1, 5)*10)),
... columns=['a', 'b', 'c', 'd', 'e'])
df2
a b c d e
0 8 1 3 7 5
Run Code Online (Sandbox Code Playgroud)
这是一个适用于第一行的输出,但我希望其余的行也被删除...
df-df2
a b c d e
0 0 8 5 -1 -1
1 NaN NaN NaN NaN NaN
2 NaN …Run Code Online (Sandbox Code Playgroud) 我想要一个简单的方法来删除数据帧内指定字符后的字符串部分.这是一个简化的例子:
DF:
obs a b c d
0 1 1-23-12 1 2 3
1 2 12-23-13 4 5 5
2 3 21-23-14 4 5 5
Run Code Online (Sandbox Code Playgroud)
我想在第一个符号后删除a列中的部分,我的预期输出是:
newdf:
obs a b c d
0 1 1 1 2 3
1 2 12 4 5 5
2 3 21 4 5 5
Run Code Online (Sandbox Code Playgroud) 我有一个大型数据框,我想使用dplyr我最近发现的优秀软件包(Wickham).我想过滤掉包含字符的列.这可能吗?
例如,在包中的flights数据集中nycflights13,如何过滤掉具有类的列character?
library(nycflights13)
data(flights)
str(flights)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 336776 obs. of 16 variables:
$ year : int 2013 2013 2013 2013 2013 2013 2013 2013 2013 2013 ...
$ month : int 1 1 1 1 1 1 1 1 1 1 ...
$ day : int 1 1 1 1 1 1 1 1 1 1 ...
$ dep_time : int 517 533 542 544 554 554 555 557 …Run Code Online (Sandbox Code Playgroud) 关于matplotlib中的yticklabels我有一个问题.
我正在尝试制作一个垂直条形图(plt.barh),然后尝试使用ax.set_yticklabels命令.我遇到的问题是它只将标签放在主要标记处!我通过的列表长度为18,但它只标出了10个吧!
请帮忙?
我使用easy_install for matplotlib-venn时遇到问题.我在使用python2.7的Windows计算机上.我怀疑路径不正确,但我不知道如何解决这个问题.谁能帮助我?我正在尝试在CMD提示符中运行easy_install命令附加输出.
C:\Python27\Scripts>easy_install matplotlib-venn
Searching for matplotlib-venn
Reading https://pypi.python.org/simple/matplotlib-venn/
Download error on https://pypi.python.org/simple/matplotlib-venn/: [Errno 11004]
getaddrinfo failed -- Some packages may not be found!
Couldn't find index page for 'matplotlib-venn' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
Download error on https://pypi.python.org/simple/: [Errno 11004] getaddrinfo fai
led -- Some packages may not be found!
No local packages or download links found for matplotlib-venn
error: Could not find suitable distribution for Requirement.parse('matplotlib-ve
nn')
install …Run Code Online (Sandbox Code Playgroud) 我有3个包含7列的数据帧.
df_a
df_b
df_c
df_a.head()
VSPD1_perc VSPD2_perc VSPD3_perc VSPD4_perc VSPD5_perc VSPD6_perc \
0 NaN NaN NaN NaN NaN NaN
3 0.189588 0.228052 0.268460 0.304063 0.009837 0
5 0.134684 0.242556 0.449054 0.168816 0.004890 0
9 0.174806 0.232150 0.381936 0.211108 0.000000 0
11 NaN NaN NaN NaN NaN NaN
VSPD7_perc
0 NaN
3 0
5 0
9 0
11 NaN
Run Code Online (Sandbox Code Playgroud)
我的目标是生成一个矩阵或数据帧,其中包含来自t检验的结果p值,并测试数据帧df_b和df_c对df_a,列为列.这是df_b中的测试列1和df_a中针对列1的df_c.我想使用dataframe(df_a)作为标准来进行统计t检验.我在statsmodels(stat.ttest_ind(x1,x2))中找到了统计测试,但是我需要帮助从测试中的p值中创建一个矩阵.有谁知道如何做到这一点...
我想使用 Likert 包,并按变量分组并绘制结果。问题是我想要可视化的变量有不同的级别。有没有解决的办法 ?
一个简单的例子来说明我的问题:
library(reshape)
library(likert)
foo <- data.frame(car = rep(c("Toyota", "BMW", "Ford"), times = 10),
satisfaction = c(1,3,4,7,7,6,2,3,5,5,5,2,4,1,7),
quality = c(1,1,3,5,4,3,6,4,3,6,6,1,7,2,7),
loyalty = c(1,1,3,5,4,3,9,4,3,10,6,1,7,2,8) )
foo[1:4] <- lapply(foo[1:4], as.factor)
likt <- likert(foo[,c(2:4)], grouping = foo$car)
plot(likt)
Run Code Online (Sandbox Code Playgroud)
错误信息:
Error in likert(foo[, c(2:4)], grouping = foo$car) :
All items (columns) must have the same number of levels
Run Code Online (Sandbox Code Playgroud) python ×6
pandas ×4
r ×4
matplotlib ×2
circlize ×1
dataframe ×1
dplyr ×1
easy-install ×1
geocoding ×1
google-maps ×1
grouping ×1
plot ×1
python-2.7 ×1
statistics ×1
statsmodels ×1
string ×1