Change index.md for data-science-tools/Pandas (#30342)
Added applying functions & selecting data in Pandas
This commit is contained in:
committed by
Christopher McCormack
parent
4ffab3310b
commit
2550fe5eff
@ -147,6 +147,40 @@ right = pd.DataFrame({'C': ['C0', 'C2', 'C3'],
|
|||||||
```python
|
```python
|
||||||
left.join(right)
|
left.join(right)
|
||||||
```
|
```
|
||||||
|
# Pandas Functions
|
||||||
|
## Information on Unique Values
|
||||||
|
```python
|
||||||
|
df['col1'].unique()
|
||||||
|
```
|
||||||
|
```python
|
||||||
|
df['col1'].nunique()
|
||||||
|
```
|
||||||
|
```python
|
||||||
|
df['col1'].value_counts()
|
||||||
|
```
|
||||||
|
## Selecting Data
|
||||||
|
```python
|
||||||
|
newdf = df[(df['col1']>2) & (df['col2']==123)]
|
||||||
|
```
|
||||||
|
```python
|
||||||
|
newdf
|
||||||
|
```
|
||||||
|
## Applying Functions
|
||||||
|
```python
|
||||||
|
def times2(x):
|
||||||
|
return x*2
|
||||||
|
```
|
||||||
|
```python
|
||||||
|
df['col1'].apply(times2)
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
df['col1'].apply(len)
|
||||||
|
```
|
||||||
|
## Permanently removing a column
|
||||||
|
```python
|
||||||
|
del df['col1']
|
||||||
|
```
|
||||||
|
|
||||||
#### More Information:
|
#### More Information:
|
||||||
1. [pandas](http://pandas.pydata.org/)
|
1. [pandas](http://pandas.pydata.org/)
|
||||||
|
Reference in New Issue
Block a user