我有一个反应本机应用程序,我正在使用 expo。
我想翻译我的移动应用程序,因此我将使用 expo-localization 和 i18n-js,它们是我在expo 文档中安装的。
然后我将其导入到我的 App.js 中,如下所示:
import * as Localization from "expo-localization";
import i18n from "i18n-js";
Run Code Online (Sandbox Code Playgroud)
我也尝试过这样导入:
import * as Localization from "expo-localization";
import { I18n } from "i18n-js";
Run Code Online (Sandbox Code Playgroud)
但导入 i18n 时出现以下错误:
Unable to resolve "make-plural" from "node_modules/i18n-js/dist/import/Pluralization.js"
Run Code Online (Sandbox Code Playgroud)
在我的 package.json 中,我有以下版本:
"i18n-js": "^4.2.3",
"expo-localization": "~13.1.0",
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
我有一个具有以下格式的数据框列:
col1 col2
A [{'Id':42,'prices':['30',’78’]},{'Id': 44,'prices':['20','47',‘89’]}]
B [{'Id':47,'prices':['30',’78’]},{'Id':94,'prices':['20']},{'Id':84,'prices':['20','98']}]
Run Code Online (Sandbox Code Playgroud)
如何将其转换为以下内容?
col1 Id price
A 42 ['30',’78’]
A 44 ['20','47',‘89’]
B 47 ['30',’78’]
B 94 ['20']
B 84 ['20','98']
Run Code Online (Sandbox Code Playgroud)
我正在考虑使用 apply 和 lambda 作为解决方案,但我不确定如何。
编辑:为了重新创建此数据框,我使用以下代码:
data = [['A', "[{'Id':42,'prices':['30','78']},{'Id': 44,'prices':['20','47','89']}]"],
['B', "[{'Id':47,'prices':['30','78']},{'Id':94,'prices':['20']},{'Id':84,'prices':['20','98']}]"]]
df = pd.DataFrame(data, columns = ['col1', 'col2'])
Run Code Online (Sandbox Code Playgroud) 我正在从输出一些 json 内容的 API 检索数据。但是,当我尝试使用以下代码将数据存储到简单的文本文件中时:
import urllib3
import json
http = urllib3.PoolManager()
url = 'http://my/endpoint/url'
myheaders = {'Content-Type':'application/json'}
mydata = {'username':'***','password':'***'}
response = http.request('POST', url, body=json.dumps(mydata).encode('UTF-8'), headers=myheaders)
print(response.status_code)
data = response.json()
with open('data.json', 'w') as f:
json.dump(data, f)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
AttributeError: 'HTTPResponse' object has no attribute 'json'
Run Code Online (Sandbox Code Playgroud)
因此,我还尝试使用 response.text 和以下代码:
file = open('data.json', 'w')
file.write(response.text)
file.close()
Run Code Online (Sandbox Code Playgroud)
但我也收到此错误:
AttributeError: 'HTTPResponse' object has no attribute 'text'
Run Code Online (Sandbox Code Playgroud)
为什么我不能将我的回复存储到简单的文本文件中?
我有一个像这样的对象数组:
const arr = [
{"id" : 1, "name" : "john", "age": 12, "fruits": "banana"},
{"id" : 2, "name" : "john", "age": 12, "fruits": "apple"}
{"id" : 3, "name" : "maria", "age": 13, "fruits": "grappes"}
{"id" : 4, "name" : "maria", "age": 13, "fruits": "blackberry"}
{"id" : 5, "name" : "camille", "age": 12, "fruits": "cherry"}
]
Run Code Online (Sandbox Code Playgroud)
我想为每个人(名字)创建一个对象并添加他们的对象。
所以最终的数组将是:
const arr = [
{"id" : 1, "name" : "john", "age": 12, "fruits": ["banana", "apple"]},
{"id" : 3, "name" : "maria", "age": …Run Code Online (Sandbox Code Playgroud) javascript ×2
python ×2
python-3.x ×2
dataframe ×1
expo ×1
httpresponse ×1
node.js ×1
pandas ×1
react-native ×1