“Carte Colonne DataFrame Python” Réponses codées

Carte Colonne DataFrame Python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  \
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Mike Rocket

Carte Colonne DataFrame Python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  \
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Mike Rocket

Carte Colonne DataFrame Python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  \
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Mike Rocket

Carte Colonne DataFrame Python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  \
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Mike Rocket

Carte Colonne DataFrame Python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  \
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Mike Rocket

Carte Colonne DataFrame Python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  \
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Mike Rocket

Carte Colonne DataFrame Python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  \
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Mike Rocket

Carte Colonne DataFrame Python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  \
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Mike Rocket

Carte Colonne DataFrame Python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  \
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Mike Rocket

Carte Colonne DataFrame Python

df = pd.DataFrame({'col1':pd.date_range('2015-01-02 15:00:07', periods=3),
                   'col2':pd.date_range('2015-05-02 15:00:07', periods=3),
                   'col3':pd.date_range('2015-04-02 15:00:07', periods=3),
                   'col4':pd.date_range('2015-09-02 15:00:07', periods=3),
                   'col5':[5,3,6],
                   'col6':[7,4,3]})

print (df)
                 col1                col2                col3  \
0 2015-01-02 15:00:07 2015-05-02 15:00:07 2015-04-02 15:00:07   
1 2015-01-03 15:00:07 2015-05-03 15:00:07 2015-04-03 15:00:07   
2 2015-01-04 15:00:07 2015-05-04 15:00:07 2015-04-04 15:00:07   

                 col4  col5  col6  
0 2015-09-02 15:00:07     5     7  
1 2015-09-03 15:00:07     3     4  
2 2015-09-04 15:00:07     6     3  

list_of_cols_to_change = ['col1','col2','col3','col4']
df[list_of_cols_to_change] = df[list_of_cols_to_change].apply(lambda x: x.dt.date)
print (df)
         col1        col2        col3        col4  col5  col6
0  2015-01-02  2015-05-02  2015-04-02  2015-09-02     5     7
1  2015-01-03  2015-05-03  2015-04-03  2015-09-03     3     4
2  2015-01-04  2015-05-04  2015-04-04  2015-09-04     6     3
Mike Rocket

Réponses similaires à “Carte Colonne DataFrame Python”

Questions similaires à “Carte Colonne DataFrame Python”

Plus de réponses similaires à “Carte Colonne DataFrame Python” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code