# Software carpentry 06/19: Slides/exo (dataframe, panda dataframe)
---
## Reading tabular data into DataFrame
---
- Read the file gapminder_gdp_americas.csv into a variable named ``americas``. Display its summary statistics.
- Using ``americas.head()`` and ``americas.tail()`` ( for help, use ``help(americas.tail)``):
1. display the first three rows of americas
2. display the last three columns of americas
---
### Writing data in a file
Using the method ```to_csv``` like ``read_csv``, write in a file the first ten rows of ``americas``. (Use ``help()`` to get more information on how to use ``to_csv()``)
---
## Pandas dataframe
---
Write an expression to find the Per Capita GDP of Serbia in 2007.
---
Do this statement produce the same output ?
```python
print(europe.iloc[0:2, 0:2])
print(europe.loc['Albania':'Belgium',
'gdpPercap_1952':'gdpPercap_1962'])
```
---
Explain what data are in first, second, third and fourth.
```python
first = pandas.read_csv('data/gapminder_all.csv',
index_col='country')
second = first[first['continent'] == 'Americas']
third = second.drop('Puerto Rico')
fourth = third.drop('continent', axis = 1)
fourth.to_csv('result.csv')
```
---
Explain what idxmin and idxmax do in this code:
```python
data = pandas.read_csv('data/gapminder_gdp_europe.csv',
index_col='country')
print(data.idxmin())
print(data.idxmax())
```
---
Using the european data, write an expression to select:
1. GDP per capita for all countries in 1982.
2. GDP per capita for Denmark for all years.
3. GDP per capita for all countries for years after 1985.
4. GDP per capita for each country in 2007 as a multiple of GDP per capita for that country in 1952
---
{"metaMigratedAt":"2023-06-14T22:04:56.889Z","metaMigratedFrom":"Content","title":"Software carpentry 06/19: Slides/exo (dataframe, panda dataframe)","breaks":true,"contributors":"[{\"id\":\"505c77d0-6054-486f-a825-d7cea45a3304\",\"add\":11391,\"del\":9680}]"}