A Data frame is a two-dimensional data structure, i.e., data is aligned in a tabular fashion in rows and columns. https://www.tutorialspoint.com/python_pandas/python_pandas_dataframe.htm
In [1]:
import pandas as pd
import numpy as np
In [2]:
from numpy.random import randn
np.random.seed(3)
In [7]:
m1=randn(5,4)
In [8]:
df1=pd.DataFrame(m1,["x","y","z","m","n"],[2008,2019,2018,2019])
In [9]:
df1
Out[9]:
In [16]:
df1=pd.DataFrame(m1,["x","y","z","m","n"],[2008,2019,2018,2020])
In [101]:
df1=pd.DataFrame(m1,' a b c d e '.split(),"r a dsj sk ".split())
In [104]:
df1
Out[104]:
In [119]:
df1[[2018]]
Out[119]:
In [10]:
df1[:'x']
Out[10]:
In [17]:
df1
Out[17]:
In [19]:
df1["sum"]=df1[2018]+df1[2019]+df1[2020]+df1[2008]
In [20]:
df1
Out[20]:
In [22]:
df1.drop("sum",axis=1)
Out[22]:
In [23]:
df1
Out[23]:
In [26]:
df1.drop("sum",axis=1,inplace=True)
In [27]:
df1
Out[27]:
In [28]:
df1.drop('n')
Out[28]:
In [29]:
df1[2008]
Out[29]:
In [30]:
df1[x]
In [32]:
df1.loc['x']
Out[32]:
In [34]:
df1.iloc[0]
Out[34]:
In [39]:
df1.loc["x",2008]
Out[39]:
In [40]:
df1
Out[40]:
In [41]:
df1.loc[['x','y'],[2018,2019]]
Out[41]:
In [43]:
type(df1.loc[['x','y'],[2018,2019]])
Out[43]:
No comments:
Post a Comment