小编The*_*ist的帖子

682
推荐指数
15
解决办法
105万
查看次数

从Pandas Datetime列中提取月份和年份

我有一个Dataframe,df,包含以下列:

df['ArrivalDate'] =
...
936   2012-12-31
938   2012-12-29
965   2012-12-31
966   2012-12-31
967   2012-12-31
968   2012-12-31
969   2012-12-31
970   2012-12-29
971   2012-12-31
972   2012-12-29
973   2012-12-29
...
Run Code Online (Sandbox Code Playgroud)

该列的元素是pandas.tslib.Timestamp.

我想要包括年份和月份.我认为会有简单的方法,但我无法弄清楚.

这是我尝试过的:

df['ArrivalDate'].resample('M', how = 'mean')
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Only valid with DatetimeIndex or PeriodIndex 
Run Code Online (Sandbox Code Playgroud)

然后我尝试了:

df['ArrivalDate'].apply(lambda(x):x[:-2])
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

'Timestamp' object has no attribute '__getitem__' 
Run Code Online (Sandbox Code Playgroud)

有什么建议?

编辑:我有点想通了.

df.index = df['ArrivalDate']
Run Code Online (Sandbox Code Playgroud)

然后,我可以使用索引重新采样另一列.

但我仍然想要一种重新配置整个列的方法.有任何想法吗?

python pandas

177
推荐指数
9
解决办法
40万
查看次数

链表的"头"是什么?

我正在使用Java链接列表,所以我试图掌握单个链表的概念.

head -> 12 -> 34 -> 56 -> null

head.next将是12(也与node1相同).然而,什么是头呢?

更新:引用和指针之间有什么区别?

Update2:所以如果head12head.next34,那么这并不意味着这个跟随函数会跳过第一个节点,看它是否为空?

public void add(Object data, int index)
    // post: inserts the specified element at the specified position in this list.
    {
        Node temp = new Node(data);
        Node current = head;
        // crawl to the requested index or the last element in the list,
        // whichever comes first
        for(int i = 1; i < index && current.getNext() != …
Run Code Online (Sandbox Code Playgroud)

java linked-list data-structures

14
推荐指数
4
解决办法
4万
查看次数

在张量流中加载 image_dataset_from_directory 时出错?

这是来自https://keras.io/examples/vision/image_classification_from_scratch/的代码

import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers

# generate a dataset 
image_size = (180,180)
batch_size = 32

train_ds = tf.keras.preprocessing.image_dataset_from_directory(
    "PetImages",
    validation_split = 0.2,
    subset = "training",
    seed = 1337,
    image_size = image_size,
    batch_size = batch_size,
)
Run Code Online (Sandbox Code Playgroud)

错误是

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-21-bb7f2d14bf63> in <module>
      3 batch_size = 32
      4 
----> 5 train_ds = tf.keras.preprocessing.image_dataset_from_directory(
      6     "PetImages",
      7     validation_split = 0.2,

AttributeError: module 'tensorflow.keras.preprocessing' has no attribute 'image_dataset_from_directory'
Run Code Online (Sandbox Code Playgroud)

我现在忽略的任何最小细节?

deep-learning conv-neural-network tensorflow jupyter-notebook

6
推荐指数
2
解决办法
9000
查看次数