Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas apply return dataframe

import pandas as pd

df_test = pd.DataFrame([
  {'dir': '/Users/uname1', 'size': 994933},
  {'dir': '/Users/uname2', 'size': 109338711},
])

def sizes(s):
  a = locale.format_string("%.1f", s['size'] / 1024.0, grouping=True) + ' KB'
  b = locale.format_string("%.1f", s['size'] / 1024.0 ** 2, grouping=True) + ' MB'
  c = locale.format_string("%.1f", s['size'] / 1024.0 ** 3, grouping=True) + ' GB'
  return a, b, c

df_test[['size_kb', 'size_mb', 'size_gb']] = df_test.apply(sizes, axis=1, result_type="expand")
Comment

PREVIOUS NEXT
Code Example
Python :: successful=true for number in range (3) print ("Attempt") if successful: print ("Successful") breal 
Python :: python length checker/fill 
Python :: python check column conditions 
Python :: group by weekhour 
Python :: the grandest staircase of them all foobar solution 
Python :: python directed graph 
Python :: var person 
Python :: python urlopen parameters 
Python :: how to find projectile angle from distance python 
Python :: import curses module in python 
Python :: Get timestamp with pyrhon 
Python :: precondition error tensorflow predict 
Python :: flask lazy response style with `make_response` 
Python :: SQLAlchemy Users to JSON code snippet 
Python :: adding text on barplot using seabron 
Python :: omr sheet python stackoverflow 
Python :: python check if more than 1 is true 
Python :: kinect python exoskeleton 
Python :: pysftp get-r 
Python :: to check weather a dictionary is empty or not in python 
Python :: numpy np sign change in df pandas zero crossing 
Python :: how to restore windows security 
Python :: mak a scipy csr sparse matrix 
Python :: pytorch pad to square 
Python :: aes in django 
Python :: pandas perform action on column 
Python :: python 3.10 windows 7 
Python :: python wikipedia 
Python :: rotate list python 
Python :: create a pandas dataframe 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =