我正在使用 Julia 1.4.2。我的版本信息是,
Julia 版本 1.4.2 Commit 44fa15b150* (2020-05-23 18:35 UTC) 平台信息:操作系统:Linux (x86_64-pc-linux-gnu) CPU:Intel(R) Core(TM) i5-6200U CPU @ 2.30 GHz WORD_SIZE:64 LIBM:libopenlibm LLVM:libLLVM-8.0.1(ORCJIT,skylake)
如何在 Julia 中从 Julia 命令模式更改为 Shell 模式?
我想执行诸如ls pwd等的os 命令,
我正在使用 StatsPlots 包来执行基本绘图。
df = DataFrame(A = 1:10, B =rand(10))
@df df plot(:A, :B)
Run Code Online (Sandbox Code Playgroud)
无论如何我可以将此绘图图像作为文件保存到我的机器(Ubuntu)中吗?
我有一个如下所示的 df,我想从 df 获取字典。
\ndf = DataFrame(id=[1, 2, 3, 4], value=["Rajesh", "John", "Jacob", "sundar"], other=[0.43, 0.42,0.54, 0.63])\n\n\xe2\x94\x82 Row \xe2\x94\x82 id \xe2\x94\x82 value \xe2\x94\x82 other \xe2\x94\x82\n\xe2\x94\x82 \xe2\x94\x82 Int64 \xe2\x94\x82 String \xe2\x94\x82 Float64 \xe2\x94\x82\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xa4\n\xe2\x94\x82 1 \xe2\x94\x82 1 \xe2\x94\x82 Rajesh \xe2\x94\x82 0.43 \xe2\x94\x82\n\xe2\x94\x82 2 \xe2\x94\x82 2 \xe2\x94\x82 John \xe2\x94\x82 0.42 \xe2\x94\x82\n\xe2\x94\x82 3 \xe2\x94\x82 3 \xe2\x94\x82 Jacob \xe2\x94\x82 0.54 \xe2\x94\x82\n\xe2\x94\x82 4 \xe2\x94\x82 4 \xe2\x94\x82 sundar \xe2\x94\x82 0.63 \xe2\x94\x82\nRun Code Online (Sandbox Code Playgroud)\n预期输出:
\n{1: 'Rajesh', 2: 'John', 3: 'Jacob', 4: 'sundar'}\nRun Code Online (Sandbox Code Playgroud)\n我知道如何在熊猫中做到这一点,
\ndf.set_index("id")["value"].to_dict()\n …Run Code Online (Sandbox Code Playgroud) 我无法从链接下载模型文件 下载 API 响应为 206。我不确定是否只有我面临这个问题还是每个人都面临这个问题?
还有其他替代方法来下载该文件吗?
我有一个包含日期和值的数据框.我必须计算每个月的值的总和.
i.e., df.groupby(pd.Grouper(freq='M'))['Value'].sum()
但问题是在我的数据集中,该月的开始日期是21,结束于20.有没有办法告诉该组从第21天到第20天到大熊猫.
假设我的数据框包含开始和结束日期,
starting_date=datetime.datetime(2015,11,21)
ending_date=datetime.datetime(2017,11,20)
Run Code Online (Sandbox Code Playgroud)
到目前为止我试过,
starting_date=df['Date'].min()
ending_date=df['Date'].max()
month_wise_sum=[]
while(starting_date<=ending_date):
temp=starting_date+datetime.timedelta(days=31)
e_y=temp.year
e_m=temp.month
e_d=20
temp= datetime.datetime(e_y,e_m,e_d)
month_wise_sum.append(df[df['Date'].between(starting_date,temp)]['Value'].sum())
starting_date=temp+datetime.timedelta(days=1)
print month_wise_sum
Run Code Online (Sandbox Code Playgroud)
我上面的代码完成了这件事.但仍在等待pythonic方式来实现它.
我最大的问题是为月份切片数据框架
例如,
2015-11-21 to 2015-12-20
Run Code Online (Sandbox Code Playgroud)
是否有任何pythonic方法来实现这一目标?提前致谢.
例如,将此视为我的数据帧.它包含来自date_range(datetime.datetime(2017,01,21),datetime.datetime(2017,10,20))
输入的日期:
Date Value
0 2017-01-21 -1.055784
1 2017-01-22 1.643813
2 2017-01-23 -0.865919
3 2017-01-24 -0.126777
4 2017-01-25 -0.530914
5 2017-01-26 0.579418
6 2017-01-27 0.247825
7 2017-01-28 -0.951166
8 2017-01-29 0.063764
9 2017-01-30 -1.960660
10 2017-01-31 1.118236
11 2017-02-01 -0.622514
12 2017-02-02 -1.416240
13 2017-02-03 1.025384
14 2017-02-04 0.448695
15 …Run Code Online (Sandbox Code Playgroud) 我有一个这样的清单:
l=[1,2,2,3,4,5,5,5]
Run Code Online (Sandbox Code Playgroud)
我们可以看到列表列表包含 5 个唯一值,总共有 8 个值。
我想要列表格式的列表中唯一值的索引。
所以输出看起来像:
indexes=[0,1,3,4,5]
Run Code Online (Sandbox Code Playgroud)
如何使用 python 以最有效的方式做到这一点?
如何在 julia 中获取所有列和特定列的 dtypes。具体来说df.dtypes,朱莉娅中的熊猫相当于什么?
例如,我有一个如下所示的 df,
? Row ? Id ? name ? item location ?
? ? Int64 ? String ? String ?
????????????????????????????????????????
? 1 ? 1 ? A ? xyz ?
? 2 ? 2 ? B ? abc ?
? 3 ? 3 ? C ? def ?
? 4 ? 4 ? D ? ghi ?
? 5 ? 5 ? E ? xyz ?
? 6 ? 6 ? F ? abc …Run Code Online (Sandbox Code Playgroud) 我有一个像下面的熊猫数据框,
col1 col2
0 12 1
1 1 7
2 54 17
3 11 191
4 3 39
5 76 2
6 18 6
Run Code Online (Sandbox Code Playgroud)
代码生成df:
df=pd.DataFrame({'col1':[12,1,54,11,3,76,18],'col2':[1,7,17,191,39,2,6]})
Run Code Online (Sandbox Code Playgroud)
我想将col1值逐个与完整的col2系列进行比较.即,将12与col2进行比较,在col2中找到小于12并计算值,然后对1执行相同的操作,然后对54执行相同操作,然后将结果存储在另一个系列中.
到目前为止我尝试过如下,
df['res']=df.apply(lambda x:len(df[df['col2']<x['col1']]),axis=1)
Run Code Online (Sandbox Code Playgroud)
它按我的预期工作.但是当系列很大时,解决这个问题的方法效果很差.
我需要有效的方法来解决这个问题.因为实际数据集包含超过百万条记录.
预期产出:
col1 col2 res
0 12 1 4
1 1 7 0
2 54 17 6
3 11 191 4
4 3 39 2
5 76 2 6
6 18 6 5
Run Code Online (Sandbox Code Playgroud) 我想在列表的每个元素中添加一个常量值作为前缀.我想做一些类似这篇文章的事情.但上面的答案正在使用for循环.我想在我的程序中使用for循环.
我的目标是我要创建它值应该是一个列表"unknown contact number 0", "unknown contact number 1","unknown contact number 2"..."unknown contact number n".这里unknown contact number是我的前缀.我想在我的列表中添加此元素.
到目前为止我试过这个,
x=pd.DataFrame(index=range(val))
print ('unknown contact number '+x.index.astype(str)).values.tolist()
Run Code Online (Sandbox Code Playgroud)
我的问题是我是否在代码中添加了更复杂的内容以避免循环?或任何其他更好的方法来解决这个问题?
提前致谢.
我有一个 df,从这个 df 我想传递 Anova 测试的参数。但问题是 df 值是动态的。如何将参数传递给scipy.stats.f_oneway这个。
例如:
num cat
0 164 type1
1 172 type1
2 168 type1
3 177 type1
4 156 type1
5 195 type1
6 178 type2
7 191 type2
8 197 type2
9 182 type2
10 185 type2
11 177 type2
12 175 type3
13 193 type3
14 178 type3
15 171 type3
16 163 type3
17 176 type3
18 155 type4
19 166 type4
20 149 type4
21 164 type4
22 …Run Code Online (Sandbox Code Playgroud) python ×5
julia ×4
pandas ×4
anova ×1
indexing ×1
julia-plots ×1
list ×1
scipy ×1
tensorflow ×1