Table of contents
1. The actual combat scene
Practical scenario: How does Pandas parse a certain data from a string and count the data more than once
2. Main points of knowledge
Three, rookie combat
Schedule now!
1. Create a python file
import pandas as pd
df = pd.read_json('market.json')
# profile形如:^AEX (Holandia)
#遍历
df['country'] = df['profile'].map( lambda x: x.split("(")[1].split(")")[0]
)
print(df.head(5))
df_counts = df["country"].value_counts()
print(df_counts)
print(list(df_counts[df_counts > 1].index))
2. Running results
profile time price change pct_change reference_price open low high country
0 ^ AEX (Netherlands) 14:12 548.73 7.95 (+ 1.47%) 540.78 546.55 544.72 550.72 Netherlands
1 ^ ATX (Austria) 14:11 2147.90 17.68 (+ 0.83%) 2130.22 2131.47 2118.71 2163.92 Austria
2 ^ ATXC (Greece) 14:13 621.82 -2.80 (-0.45%) 624.62 627.48 621.82 631.70 Greece
3 ^ BEL20 (Belgium) 14:11 3251.39 30.51 (+ 0.95%) 3220.88 3252.21 3228.77 3266.11 Belgium
4 ^ BUX (Hungary ) 14:12 32 831.01 534.27 (+ 1.65%) 32 296.74 32 421.05 32421.05 32 865.43 Hungary
Russia 2
Great Britain 2
Netherlands 1
Finland 1
Turkey 1
Switzerland 1
Czech Republic 1
Portugal 1
Norway 1
Sweden 1
Denmark 1
Austria 1
Spain 1
Italy 1
Germany 1
France 1
Hungary 1
Belgium 1
Greece 1
Poland 1
Name: country, dtype: int64
['Russia', 'United Kingdom' ]
Rookie combat, keep learning!