pandas_dataframe_and_rows
import pandas as pd
df = pd.DataFrame(
{"a" : [4 ,5, 6],
"b" : [7, 8, 9],
"c" : [10, 11, 12]},
index = [1, 2, 3])
df
a | b | c | |
---|---|---|---|
1 | 4 | 7 | 10 |
2 | 5 | 8 | 11 |
3 | 6 | 9 | 12 |
df.loc[3, "a"]
6
df.loc[[1, 2], ["a", "b"]]
a | b | |
---|---|---|
1 | 4 | 7 |
2 | 5 | 8 |
df = pd.DataFrame(
[[4, 7, 10],
[5, 8, 11],
[6, 9, 12]],
index=[1, 2, 3],
columns=["a", 'b', 'c'])
df
a | b | c | |
---|---|---|---|
1 | 4 | 7 | 10 |
2 | 5 | 8 | 11 |
3 | 6 | 9 | 12 |
import numpy as np
df = pd.DataFrame(
{"a" : [4 ,5, 6, 6, np.nan],
"b" : [7, 8, np.nan, 9, 9],
"c" : [10, 11, 12, np.nan, 12]},
index = pd.MultiIndex.from_tuples(
[('d',1),('d',2),('e',2),('e',3),('e',4)],
names=['n','v']))
df
a | b | c | ||
---|---|---|---|---|
n | v | |||
d | 1 | 4.0 | 7.0 | 10.0 |
2 | 5.0 | 8.0 | 11.0 | |
e | 2 | 6.0 | NaN | 12.0 |
3 | 6.0 | 9.0 | NaN | |
4 | NaN | 9.0 | 12.0 |