Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用其他两列的输入创建列表列_Python_Python 2.7_Pandas_Dataframe - Fatal编程技术网

Python 使用其他两列的输入创建列表列

Python 使用其他两列的输入创建列表列,python,python-2.7,pandas,dataframe,Python,Python 2.7,Pandas,Dataframe,示例df: id start end a 2018-04-01 2018-04-03 b 2018-04-01 2018-04-03 c 2018-04-02 2018-04-03 理想输出A id start end lst a 2018-04-01 2018-04-03 [2018-04-01, 2018-04-02, 2018-04-03] b 2018-04-01 2018-04-03 [

示例df:

id   start       end
a    2018-04-01  2018-04-03
b    2018-04-01  2018-04-03
c    2018-04-02  2018-04-03
理想输出A

id   start       end          lst
a    2018-04-01  2018-04-03   [2018-04-01, 2018-04-02, 2018-04-03]
b    2018-04-01  2018-04-03   [2018-04-01, 2018-04-02, 2018-04-03]
c    2018-04-02  2018-04-03   [2018-04-02, 2018-04-03]
到目前为止我所拥有的(不起作用)

一旦得到理想的输出A,我将尝试运行以下代码以获得理想的输出B

lst1 = ['a','b','c']
lst2 = ['b','c','d']
lst3 = ['c','d','e']

comp_lst = lst1 + lst2 +lst3

from collections import Counter
Counter(comp_lst)
Counter({'a': 1, 'b': 2, 'c': 3, 'd': 2, 'e': 1})
Counter({'2018-04-01': 2, '2018-04-02': 3, '2018-04-03': 3})
理想输出B

lst1 = ['a','b','c']
lst2 = ['b','c','d']
lst3 = ['c','d','e']

comp_lst = lst1 + lst2 +lst3

from collections import Counter
Counter(comp_lst)
Counter({'a': 1, 'b': 2, 'c': 3, 'd': 2, 'e': 1})
Counter({'2018-04-01': 2, '2018-04-02': 3, '2018-04-03': 3})
任何帮助都将不胜感激

IIUC

df['lst']=[pd.date_range(start=x,end=y,freq='D').date.astype(str).tolist() for x , y in zip(df.start,df.end)]
Counter(sum(df['lst'].tolist(),[]))
Out[327]: Counter({'2018-04-01': 2, '2018-04-02': 3, '2018-04-03': 3})
用于构造列表。