Difference makes the DIFFERENCE
import numpy as np
import pandas as pd
import seaborn as sns
planets = sns.load_dataset('planets')
planets = pd.DataFrame(planets)
dfplanets = planets
dfplanets.info()
dfplanets.method.unique()
s = 'Radial Velocity'
s.split()
[x[0] for x in s.split()]
"".join([x[0] for x in s.split()])
s = 'Pulsation Timing Variations'
"".join([x[0] for x in s.split()])
short_names = {}
for x in planets.method.unique():
short_names[x] = "".join([x[0] for x in x.split()])
short_names
for i, r in planets.iterrows():
planets.loc[i, 'short_method'] = short_names.get(r['method'], r['method'])
planets.head()
planets.tail()
s = "Radial Velocity"
s.split()
p = s.split()
p
p[0]
p[1]
[x[0] for x in p]
"".join([x[0] for x in p])
s = '-'
str = ['a', 'b','c']
s.join(str)
s = '-'
str1 = ['a', 'b','c']
str2 = ['1', '2', '3']
s.join(str1, str2)
planets.method.unique()
s = 'Orbital Brightness Modulation'
s.split()
s.split()[1]
[x[0] for x in s.split()]
"".join(x[0] for x in s.split())
short_names = planets.method.unique()
print(x[i] for i in planets.method.unique())
print(short_names)
short_names[1]
short_names[2].split()
"".join([x[0] for x in short_names[5].split()])
planets_dic = {}
for s in planets.method.unique():
planets_dic[s] = "".join([x[0] for x in s.split()])
planets_dic
for i, r in planets.iterrows():
planets.loc[i, "abbrev"] = planets_dic.get(r['method'], r['method'])
planets.head()
planets.tail()
for i, r in planets.iterrows():
planets.loc[i, "abbre"] = planets_dic.get(r['method'], r['method'])
planets.head()
planets.drop('abbre', axis=1, inplace = True)
planets.head()
df_planets = sns.load_dataset('planets')
method_list = df_planets.method.unique()
method_list
method_dic = {}
for i in method_list:
method_dic[i] = "".join(x[0] for x in i.split())
method_dic
def method_shorts(s):
return method_dic.get(s, s)
df_planets['short_method'] = df_planets['method'].apply(method_shorts)
df_planets