我有一个名为st1.csv的简单2列csv文件:
GRID St1
1457 614
1458 657
1459 679
1460 732
1461 754
1462 811
1463 748
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试读取csv文件时,未加载第一列:
a = pandas.DataFrame.from_csv('st1.csv')
a.columns
Run Code Online (Sandbox Code Playgroud)
输出:
Index([u'ST1'], dtype=object)
Run Code Online (Sandbox Code Playgroud)
为什么没有读取第一列?
有没有办法使用numpy.percentile函数来计算加权百分位数?或者是否有人知道替代python函数来计算加权百分位数?
谢谢!
我有以下数据帧:
a b x y
0 1 2 3 -1
1 2 4 6 -2
2 3 6 9 -3
3 4 8 12 -4
Run Code Online (Sandbox Code Playgroud)
如何移动列b和x,使它们成为数据框中的最后2列?我想按名称指定b和x,而不是其他列.
我有一个命名元组,我赋值如下:
class test(object):
self.CFTs = collections.namedtuple('CFTs', 'c4annual c4perren c3perren ntfixing')
self.CFTs.c4annual = numpy.zeros(shape=(self.yshape, self.xshape))
self.CFTs.c4perren = numpy.zeros(shape=(self.yshape, self.xshape))
self.CFTs.c3perren = numpy.zeros(shape=(self.yshape, self.xshape))
self.CFTs.ntfixing = numpy.zeros(shape=(self.yshape, self.xshape))
Run Code Online (Sandbox Code Playgroud)
有没有办法循环命名元组的元素?我试过这样做,但不起作用:
for fld in self.CFTs._fields:
self.CFTs.fld= numpy.zeros(shape=(self.yshape, self.xshape))
Run Code Online (Sandbox Code Playgroud) 我试图基于foll连接数据帧.2个csv文件:
df_a:https://www.dropbox.com/s/slcu7o7yyottujl/df_current.csv ? dl = 0
df_b:https://www.dropbox.com/s/laveuldraurdpu1/df_climatology.csv ? dl = 0
这两个都具有相同的列数和名称.但是,当我这样做时:
pandas.concat([df_a, df_b])
Run Code Online (Sandbox Code Playgroud)
我收到错误:
AssertionError: Number of manager items must equal union of block items
# manager items: 20, # tot_items: 21
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?
如何用中值标记seaborn图中的每个箱图?
例如
import seaborn as sns
sns.set_style("whitegrid")
tips = sns.load_dataset("tips")
ax = sns.boxplot(x="day", y="total_bill", data=tips)
Run Code Online (Sandbox Code Playgroud)
如何用中位数或平均值标记每个箱图?
对于我正在编写的一些Python代码,我想在R中使用等效的子命令.
这是我的数据:
col1 col2 col3 col4 col5
100002 2006 1.1 0.01 6352
100002 2006 1.2 0.84 304518
100002 2006 2 1.52 148219
100002 2007 1.1 0.01 6292
10002 2006 1.1 0.01 5968
10002 2006 1.2 0.25 104318
10002 2007 1.1 0.01 6800
10002 2007 4 2.03 25446
10002 2008 1.1 0.01 6408
Run Code Online (Sandbox Code Playgroud)
我想子集基于内容的数据col1和col2.(col1中的唯一值为100002和10002,col2中的唯一值为2006,2007和2008.)
这可以使用subset命令在R中完成,Python中有类似的东西吗?
我有这个人.数据帧:
DF
A B
0 23 12
1 21 44
2 98 21
Run Code Online (Sandbox Code Playgroud)
如何删除列名A,并B从该数据帧?一种方法可能是将其写入csv文件,然后在指定header = None时读取它.如果没有写出csv并重新阅读,有没有办法做到这一点?
如何以有效的方式访问和修改2D numpy阵列的周围8个单元?
我有一个像这样的2D numpy数组:
arr = np.random.rand(720, 1440)
Run Code Online (Sandbox Code Playgroud)
对于每个网格单元,我想减少中心单元的10%,周围的8个单元(角单元更少),但仅当周围单元值超过0.25时.我怀疑这样做的唯一方法是使用for循环但是想看看是否有更好/更快的解决方案.
- 编辑:对于基于循环的soln:
arr = np.random.rand(720, 1440)
for (x, y), value in np.ndenumerate(arr):
# Find 10% of current cell
reduce_by = value * 0.1
# Reduce the nearby 8 cells by 'reduce_by' but only if the cell value exceeds 0.25
# [0] [1] [2]
# [3] [*] [5]
# [6] [7] [8]
# * refers to current cell
# cell [0]
arr[x-1][y+1] = arr[x-1][y+1] * reduce_by if arr[x-1][y+1] > 0.25 else arr[x-1][y+1] …Run Code Online (Sandbox Code Playgroud) 我正在使用scikit额外的树分类器:
model = ExtraTreesClassifier(n_estimators=10000, n_jobs=-1, random_state=0)
Run Code Online (Sandbox Code Playgroud)
一旦模型被拟合并用于预测类,我想找出每个特征对特定类预测的贡献.我如何在scikit中学习呢?是否可以使用额外的树分类器或我是否需要使用其他模型?
python ×10
pandas ×4
numpy ×3
arrays ×1
csv ×1
dataframe ×1
matplotlib ×1
namedtuple ×1
percentile ×1
r ×1
scikit-learn ×1
seaborn ×1
subset ×1
weighted ×1