Professional Documents
Culture Documents
"Name" 'Harry' 'Rohan' 'Skillf' 'Subh' "Marks" "City" 'Rampur' 'Kolkata' 'Bareley' 'Antartica'
"Name" 'Harry' 'Rohan' 'Skillf' 'Subh' "Marks" "City" 'Rampur' 'Kolkata' 'Bareley' 'Antartica'
"Name" 'Harry' 'Rohan' 'Skillf' 'Subh' "Marks" "City" 'Rampur' 'Kolkata' 'Bareley' 'Antartica'
In [1]:
import numpy as np
import pandas as pd
In [2]:
dict1={"name":['harry','rohan','skillf','subh'],
"marks":[943,43,45,345],
"city":['rampur','kolkata','bareley','antartica']}
In [3]:
df =pd.DataFrame(dict1)
In [4]:
df
Out[4]:
1 rohan 43 kolkata
2 skillf 45 bareley
In [5]:
df.to_csv('friends')
In [6]:
df
Out[6]:
1 rohan 43 kolkata
2 skillf 45 bareley
In [7]:
df.to_csv('friends_index_false.csv', index=False)
localhost:8889/notebooks/Untitled.ipynb 1/23
19/10/2020 Untitled - Jupyter Notebook
In [8]:
df
Out[8]:
1 rohan 43 kolkata
2 skillf 45 bareley
In [9]:
df.tail(2)
Out[9]:
2 skillf 45 bareley
In [10]:
df.head(2)
Out[10]:
1 rohan 43 kolkata
localhost:8889/notebooks/Untitled.ipynb 2/23
19/10/2020 Untitled - Jupyter Notebook
In [11]:
df.describe()
Out[11]:
marks
count 4.000000
mean 344.000000
std 423.793975
min 43.000000
25% 44.500000
50% 195.000000
75% 494.500000
max 943.000000
In [12]:
vivek=pd.read_csv('vivek.csv')
In [13]:
vivek
Out[13]:
0 0 0 0 0 0 0 15462 50 rampur
1 1 1 1 1 1 1 58565 43 kolkata
In [14]:
vivek['Speed']
Out[14]:
0 50
1 43
2 445
3 345
Name: Speed, dtype: int64
localhost:8889/notebooks/Untitled.ipynb 3/23
19/10/2020 Untitled - Jupyter Notebook
In [15]:
vivek['Speed'][0]=50
<ipython-input-15-d9680192b8b7>:1: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
In [16]:
vivek
Out[16]:
0 0 0 0 0 0 0 15462 50 rampur
1 1 1 1 1 1 1 58565 43 kolkata
In [17]:
vivek.to_csv('vivek.csv')
In [18]:
vivek.index =['first','second','third','fourth']
localhost:8889/notebooks/Untitled.ipynb 4/23
19/10/2020 Untitled - Jupyter Notebook
In [19]:
vivek
Out[19]:
first 0 0 0 0 0 0 15462 50
second 1 1 1 1 1 1 58565 43
In [20]:
ser=pd.Series(np.random.rand(34))
In [21]:
ser.head()
Out[21]:
0 0.898952
1 0.862269
2 0.833553
3 0.062381
4 0.436343
dtype: float64
In [22]:
type(ser)
Out[22]:
pandas.core.series.Series
In [23]:
newdf=pd.DataFrame(np.random.rand(34))
localhost:8889/notebooks/Untitled.ipynb 5/23
19/10/2020 Untitled - Jupyter Notebook
In [24]:
newdf.head()
Out[24]:
0 0.168435
1 0.342793
2 0.913369
3 0.303032
4 0.174320
In [25]:
newwdf=pd.DataFrame(np.random.rand(34,5), index=np.arange(34))
In [26]:
newwdf.head()
Out[26]:
0 1 2 3 4
In [27]:
type(newdf)
Out[27]:
pandas.core.frame.DataFrame
localhost:8889/notebooks/Untitled.ipynb 6/23
19/10/2020 Untitled - Jupyter Notebook
In [28]:
newwdf.describe()
Out[28]:
0 1 2 3 4
In [29]:
newwdf.dtypes
Out[29]:
0 float64
1 float64
2 float64
3 float64
4 float64
dtype: object
In [30]:
newwdf[0][0]='vivek'
In [31]:
newwdf.dtypes
Out[31]:
0 object
1 float64
2 float64
3 float64
4 float64
dtype: object
localhost:8889/notebooks/Untitled.ipynb 7/23
19/10/2020 Untitled - Jupyter Notebook
In [32]:
newwdf.head()
Out[32]:
0 1 2 3 4
In [33]:
newwdf.index
Out[33]:
In [34]:
newwdf.columns
Out[34]:
localhost:8889/notebooks/Untitled.ipynb 8/23
19/10/2020 Untitled - Jupyter Notebook
In [35]:
reform=newwdf.to_numpy()
print(reform.shape)
reform
(34, 5)
Out[35]:
In [36]:
newwdf.T
Out[36]:
0 1 2 3 4 5 6 7
5 rows × 34 columns
In [37]:
newwdf.head()
Out[37]:
0 1 2 3 4
localhost:8889/notebooks/Untitled.ipynb 10/23
19/10/2020 Untitled - Jupyter Notebook
In [38]:
sorted_newdf1=newwdf.sort_index(axis=0,ascending=False)
sorted_newdf1.head()
Out[38]:
0 1 2 3 4
In [39]:
sorted_newdf2=newwdf.sort_index(axis=1,ascending=False)
sorted_newdf2.head()
Out[39]:
4 3 2 1 0
In [40]:
newwdf.head()
Out[40]:
0 1 2 3 4
localhost:8889/notebooks/Untitled.ipynb 11/23
19/10/2020 Untitled - Jupyter Notebook
In [41]:
newdf2=newwdf
In [42]:
newdf2[0][0]=22332
<ipython-input-42-b6b88ecefaab>:1: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
In [43]:
newwdf.head()
Out[43]:
0 1 2 3 4
In [44]:
newdf2=newwdf.copy()
In [45]:
newdf2[0][0]=54625659
<ipython-input-45-5a7394a84071>:1: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
localhost:8889/notebooks/Untitled.ipynb 12/23
19/10/2020 Untitled - Jupyter Notebook
In [46]:
newwdf.head()
Out[46]:
0 1 2 3 4
In [47]:
newwdf.loc[0,0]=1231
In [48]:
newwdf.head(2)
Out[48]:
0 1 2 3 4
In [49]:
newwdf.columns=list("ABCDE")
In [50]:
newwdf.head()
Out[50]:
A B C D E
localhost:8889/notebooks/Untitled.ipynb 13/23
19/10/2020 Untitled - Jupyter Notebook
In [51]:
newwdf.loc[0,'A']=99
In [52]:
newwdf.head()
Out[52]:
A B C D E
In [53]:
newdrop=newwdf.drop('A', axis=1)
newdrop.head()
Out[53]:
B C D E
In [54]:
newwdf.head()
Out[54]:
A B C D E
localhost:8889/notebooks/Untitled.ipynb 14/23
19/10/2020 Untitled - Jupyter Notebook
In [55]:
newwdf.head()
Out[55]:
A B C D E
In [56]:
newwdf.loc[[1,2],:]
Out[56]:
A B C D E
In [57]:
newwdf.loc[(newwdf['A']<0.3)]
Out[57]:
A B C D E
localhost:8889/notebooks/Untitled.ipynb 15/23
19/10/2020 Untitled - Jupyter Notebook
In [58]:
newwdf.head()
Out[58]:
A B C D E
In [59]:
newwdf.iloc[0,4]
Out[59]:
0.2406102893950759
In [60]:
newwdf.head()
Out[60]:
A B C D E
In [61]:
newwdf.iloc[[0,1],[1,2]]
Out[61]:
B C
0 0.169806 0.801854
1 0.178549 0.611301
localhost:8889/notebooks/Untitled.ipynb 16/23
19/10/2020 Untitled - Jupyter Notebook
In [62]:
newwdf.iloc[[0,5],[1,2]]
Out[62]:
B C
0 0.169806 0.801854
5 0.147095 0.811327
In [63]:
newwdf.head(3)
Out[63]:
A B C D E
In [64]:
drop1=newwdf.drop([3])
drop1.head()
Out[64]:
A B C D E
localhost:8889/notebooks/Untitled.ipynb 17/23
19/10/2020 Untitled - Jupyter Notebook
In [65]:
drop2=newwdf.drop(['B'],axis=1)
drop2.head()
Out[65]:
A C D E
In [66]:
drop3=newwdf.drop(['A','C'],axis=1)
drop3.head()
Out[66]:
B D E
In [67]:
newwdf.drop([1,5], axis=0,inplace=True)
In [68]:
newwdf.reset_index().head()
Out[68]:
index A B C D E
localhost:8889/notebooks/Untitled.ipynb 18/23
19/10/2020 Untitled - Jupyter Notebook
In [69]:
newwdf.reset_index(drop=True).head()
Out[69]:
A B C D E
In [70]:
newwdf['B'].isnull().head()
Out[70]:
0 False
2 False
3 False
4 False
6 False
Name: B, dtype: bool
In [71]:
newwdf['B']=None
In [72]:
newwdf.head()
Out[72]:
A B C D E
localhost:8889/notebooks/Untitled.ipynb 19/23
19/10/2020 Untitled - Jupyter Notebook
In [73]:
newwdf['B'].isnull().head()
Out[73]:
0 True
2 True
3 True
4 True
6 True
Name: B, dtype: bool
In [74]:
newwdf.head()
Out[74]:
A B C D E
In [75]:
newwdf.loc[:,['B']]=None
In [76]:
newwdf.head()
Out[76]:
A B C D E
In [77]:
newwdf.loc[:,['B']]=10
localhost:8889/notebooks/Untitled.ipynb 20/23
19/10/2020 Untitled - Jupyter Notebook
In [78]:
newwdf.head()
Out[78]:
A B C D E
In [79]:
In [80]:
df.head()
Out[80]:
In [81]:
df.dropna(how='all',axis=1)
Out[81]:
localhost:8889/notebooks/Untitled.ipynb 21/23
19/10/2020 Untitled - Jupyter Notebook
In [82]:
df.drop_duplicates(subset=['name'])
Out[82]:
In [83]:
df.drop_duplicates(subset=['name'], keep=False)
Out[83]:
In [84]:
df.shape
Out[84]:
(3, 3)
In [85]:
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 3 entries, 0 to 2
Data columns (total 3 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 name 3 non-null object
1 toy 2 non-null object
2 born 1 non-null datetime64[ns]
dtypes: datetime64[ns](1), object(2)
memory usage: 200.0+ bytes
localhost:8889/notebooks/Untitled.ipynb 22/23
19/10/2020 Untitled - Jupyter Notebook
In [86]:
df['name'].value_counts(dropna=False)
Out[86]:
Alfred 2
Batman 1
Name: name, dtype: int64
In [87]:
df['toy'].value_counts(dropna=False)
Out[87]:
Bullwhip 1
NaN 1
NaN 1
Name: toy, dtype: int64
In [88]:
df.isnull()
Out[88]:
In [ ]:
localhost:8889/notebooks/Untitled.ipynb 23/23