Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
61 views
in Technique[技术] by (71.8m points)

How to format strings differently in pandas python?

I have some base.

df = pd.DataFrame([
    [time.strftime("%Y-%m-%d", time.gmtime(1611161411.46177)),405.52,39,46,633],
    [time.strftime("%Y-%m-%d", time.gmtime(1611161911.46177)),406.52,41,103,582],
    [time.strftime("%Y-%m-%d", time.gmtime(1611161911.46177)),406.52,41,146,544],
    [time.strftime("%Y-%m-%d", time.gmtime(1611161911.46177)),406.52,41,164,532]], columns=['Date','Balance',"In sell","Quantity","Profit"])

this is what it looks like :

this is what it looks like

I want to apply to each row:

df = df.style.bar()

This is how I would like to see my final table: This is how I would like to see my final table

only with formatting of all rows. I ask for your help in this matter.

question from:https://stackoverflow.com/questions/65857353/how-to-format-strings-differently-in-pandas-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

try:

df.style.bar(subset=pd.IndexSlice[1:2, ['Quantity', 'Profit']], align='mid', color=['#5fba7d'])

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...