我想使用来自sklearn的StandardScaler的几个方法.是否可以在我的集合的某些列/功能上使用这些方法,而不是将它们应用于整个集合.
例如,该集合是sklearn:
data = pd.DataFrame({'Name' : [3, 4,6], 'Age' : [18, 92,98], 'Weight' : [68, 59,49]})
   Age  Name  Weight
0   18     3      68
1   92     4      59
2   98     6      49
col_names = ['Name', 'Age', 'Weight']
features = data[col_names]
Run Code Online (Sandbox Code Playgroud)
我适合并改造了 StandardScaler
scaler = StandardScaler().fit(features.values)
features = scaler.transform(features.values)
scaled_features = pd.DataFrame(features, columns = col_names)
       Name       Age    Weight
0 -1.069045 -1.411004  1.202703
1 -0.267261  0.623041  0.042954
2  1.336306  0.787964 -1.245657
Run Code Online (Sandbox Code Playgroud)
但当然名称不是浮点数而是字符串,我不想将它们标准化.我怎样才能应用data和data功能只在列fit和transform?
当连接到远程 SSH 主机并且我的 Mac 在几分钟不活动后进入睡眠状态时,我必须重新加载整个窗口才能在返回时重新建立连接。
当连接由于不活动而被切断时,避免这种等待时间的最节能的方法是什么?有没有办法在不完全禁用 Mac 上的睡眠模式的情况下保持会话处于活动状态(或者更顺利地重新连接到会话,而无需重新加载整个窗口)?如果没有,是否有办法仅在 VS Code 远程会话处于活动状态时自动禁用睡眠模式?
我有一个Gatsby项目,它有两个不同类型的内容非常相似的GraphQL查询:常规页面和维基文章.
页面由slug
export const query = graphql`
  query($slug: String!) {
    page: contentfulPage(slug: {eq: $slug}) {
      title
      slug
      body {
        remark: childMarkdownRemark {
          excerpt
          html
          headings {
            value
            depth
          }
        }
      }
      updatedAt(formatString: "D. MMM YYYY")
      authors {
        name
        email
      }
    }
  }
`
Run Code Online (Sandbox Code Playgroud)
由slug撰写的Wiki文章
export const query = graphql`
  query($slug: String!) {
    article: contentfulWikiArticle(slug: {eq: $slug}) {
      title
      slug
      body {
        remark: childMarkdownRemark {
          excerpt
          html
          headings {
            value
            depth
          }
        }
      }
      updatedAt(formatString: "D. MMM YYYY")
      authors {
        name …Run Code Online (Sandbox Code Playgroud) 我花了一些时间徒劳地寻找我的问题的答案,所以我认为一个新的问题是有序的.考虑这个情节:
轴标签使用科学记数法.在y轴上,一切都很好.但是,我已经尝试并且未能摆脱Python在右下角添加的缩放因子.我想要完全删除这个因素,只需通过轴标题中的单位指示它,或者将它乘以每个刻度标签.一切都看起来比这丑陋1e14.
这是代码:
import numpy as np data_a = np.loadtxt('exercise_2a.txt')
import matplotlib as mpl 
font = {'family' : 'serif',
        'size'   : 12} 
mpl.rc('font', **font)
import matplotlib.pyplot as plt 
fig = plt.figure() 
subplot = fig.add_subplot(1,1,1)
subplot.plot(data_a[:,0], data_a[:,1], label='$T(t)$', linewidth=2)
subplot.set_yscale('log')               
subplot.set_xlabel("$t[10^{14}s]$",fontsize=14) 
subplot.set_ylabel("$T\,[K]$",fontsize=14) 
plt.xlim(right=max(data_a [:,0])) 
plt.legend(loc='upper right')
plt.savefig('T(t).pdf', bbox_inches='tight')
Run Code Online (Sandbox Code Playgroud)
更新:将Will的实现结合scientificNotation到我的脚本中,情节现在看起来像
如果你问我,好多了.对于想要采用其中某些部分的人来说,这是完整的代码:
import numpy as np
data = np.loadtxt('file.txt')
import matplotlib as mpl
font = {'family' : 'serif',
        'size'   : 16}
mpl.rc('font', **font)
import matplotlib.pyplot as plt
fig = …Run Code Online (Sandbox Code Playgroud) 我的package.json脚本部分看起来像这样。
"scripts": {
  "prestart": "mongod",
  "start": "NODE_ENV=prod node server.js",
  "poststop": "mongo admin --eval 'db.shutdownServer()'",
  "predev": "mongod",
  "dev": "NODE_ENV=dev nodemon server.js"
},
Run Code Online (Sandbox Code Playgroud)
我使用 pre- 和 post 钩子mongod在启动我的服务器之前启动。然后我使用ctrl+杀死我的服务器c。不幸的是,这不会执行poststop脚本。结果,npm/yarn start/dev第二次调用会抛出错误并中止,因为mongod已经在运行。
另一个 mongod 实例已经在 /data/db 目录上运行,正在终止
我可以以某种方式实现poststop在ctrl+ c?
我有一个 Gatsby GraphQL 查询,用于获取按日期排序并按类别过滤的帖子列表。
{
  posts: allContentfulPost(
    sort: {fields: [date], order: DESC},
    filter: {category: {slug: {eq: $slug}}}
  ) {
    edges {
      node {
        title {
          title
        }
        date
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)
现在什么时候$slug是空字符串"",我明白了
{
  "data": {
    "posts": null
  }
}
Run Code Online (Sandbox Code Playgroud)
有没有办法获取所有帖子?
给定一个数据框,
df = pd.DataFrame(pd.np.random.randint(0, 10, (4,3)), columns=['a','b','c'])
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以将其某一列放到原处并在同一行上返回它?如果我尝试
a = df.drop(columns=['a'], inplace=True)
Run Code Online (Sandbox Code Playgroud)
我懂了a == None。相比之下,这似乎很笨拙:
a = df['a']
df.drop(columns=['a'], inplace=True)
Run Code Online (Sandbox Code Playgroud) contentful ×2
gatsby ×2
graphql ×2
pandas ×2
python ×2
data-science ×1
dry ×1
graphql-js ×1
macos ×1
matplotlib ×1
mongodb ×1
npm-scripts ×1
plot ×1
scale ×1
scikit-learn ×1
sigterm ×1
sleep-mode ×1
ssh ×1
yarnpkg ×1