pilhoon / wiki_public

0 stars 0 forks source link

pandas #5

Open pilhoon opened 4 years ago

pilhoon commented 4 years ago

styling

def color_negative_red(val):
    """
    Takes a scalar and returns a string with
    the css property `'color: red'` for negative
    strings, black otherwise.
    """
    color = 'red' if val < 0 else 'black'
    return 'color: %s' % color

s = df.style.applymap(color_negative_red)

ref

pilhoon commented 4 years ago

col(or row) index rename

map을 이용하는 것이 핵심 row는 다음과 같이

>>> df.rename(index={0: "x", 1: "y", 2: "z"})
   A  B
x  1  4
y  2  5
z  3  6

column은 다음과 같이

>>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
>>> df.rename(columns={"A": "a", "B": "c"})
   a  c
0  1  4
1  2  5
2  3  6

column은 다음과 같이 해도 되었음

df.columns = [...]
pilhoon commented 4 years ago

csv

load

data = pd.read_csv("filename.csv")

save

Screen Shot 2020-04-02 at 9 34 18 PM

ref

pilhoon commented 4 years ago

pd.options.display.max_columns = None

ref

pd.options.display.min_rows = 1000
pd.options.display.max_rows = 1000
pd.options.display.max_columns = 1000
pilhoon commented 4 years ago

to_numpy

df.to_numpy() #