lab3
unknown
python
3 years ago
1.6 kB
7
Indexable
# coding: utf-8
# In[40]:
import numpy as np
import pandas as pd
# In[41]:
lables=['a','b','c']
my_list=[10,20,30]
arr=np.array([10,20,30])
d={'a':10,'b':20,'c':30}
# In[42]:
pd.Series(data=my_list)
# In[43]:
pd.Series(d)
# In[44]:
pd.Series([sum,print,len])
# In[45]:
ser1=pd.Series([1,2,3,4], index=['USA','Germany','USSR','Japan'])
# In[48]:
ser2=pd.Series([1,2,5,4], index=['USA','Germany','Italy','Japan'])
# In[49]:
ser1+ser2
# In[52]:
from numpy.random import randn
np.random.seed(101)
# In[53]:
df=pd.DataFrame(randn(5,4),index='A B C D E'.split(),columns = 'W X Y Z'.split())
# In[54]:
df
# In[57]:
df[['W','Z']]
# In[58]:
df.W
# In[59]:
type(df['W'])
# In[60]:
df['new']=df['W'] + df['Y']
# In[61]:
df
# In[63]:
df.drop('new',axis=1)
# In[64]:
df
# In[65]:
df.drop('new',axis=1,inplace=True)
# In[66]:
df
# In[67]:
df.drop('E',axis=0,inplace=True)
# In[68]:
df
# In[69]:
df.loc['A']
# In[70]:
df.loc['B','Y']
# In[71]:
df>0
# In[72]:
df
# In[75]:
df[df>0]
# In[79]:
df[df['W']>0]['Y']
# In[81]:
df[df['W']>0]
# In[82]:
df[df['W']>0][['Y','X']]
# In[85]:
df[(df['W']>0)& (df['Y']>0)]
# In[86]:
df.reset_index()
# In[109]:
newind='CA NY PL CA'.split()
df['States']=newind
# In[110]:
df
# In[112]:
df.set_index('States',inplace=True)
# In[113]:
df
# In[118]:
import matplotlib.pyplot as plt
from matplotlib import figure
df = pd.read_csv('C://Users//Admin//CSE_Avirup_Python/example.csv')
print(df)
Editor is loading...